Update app.py
Browse files
app.py
CHANGED
@@ -48,20 +48,21 @@ def chat_fn(message, history):
|
|
48 |
|
49 |
context = get_context(message)
|
50 |
|
51 |
-
# β
|
52 |
if not context.strip():
|
53 |
if is_greeting(message):
|
54 |
-
return "π
|
55 |
-
return "
|
56 |
|
57 |
-
# β
Construct
|
58 |
messages = [
|
59 |
{
|
60 |
"role": "system",
|
61 |
"content": (
|
62 |
-
"You are a
|
63 |
-
"
|
64 |
-
"
|
|
|
65 |
"\n\nContext:\n" + context
|
66 |
)
|
67 |
}
|
@@ -71,13 +72,12 @@ def chat_fn(message, history):
|
|
71 |
messages.append({"role": "user", "content": user})
|
72 |
messages.append({"role": "assistant", "content": assistant})
|
73 |
|
74 |
-
|
75 |
-
messages.append({"role": "user", "content": message + "\n\nPlease answer briefly."})
|
76 |
|
77 |
payload = {
|
78 |
"model": MODEL,
|
79 |
"messages": messages,
|
80 |
-
"max_tokens":
|
81 |
}
|
82 |
|
83 |
try:
|
@@ -111,7 +111,7 @@ async def chat_api(request: Request):
|
|
111 |
demo = gr.ChatInterface(
|
112 |
fn=chat_fn,
|
113 |
title="π¬ CODEX MIRXA KAMRAN",
|
114 |
-
description="
|
115 |
theme="soft"
|
116 |
)
|
117 |
|
|
|
48 |
|
49 |
context = get_context(message)
|
50 |
|
51 |
+
# β
Handle greetings when no context found
|
52 |
if not context.strip():
|
53 |
if is_greeting(message):
|
54 |
+
return "π Hey there! How can I help you today?"
|
55 |
+
return "π€ Hmm, Iβm not sure about that. Could you rephrase your question?"
|
56 |
|
57 |
+
# β
Construct prompt with friendly natural tone
|
58 |
messages = [
|
59 |
{
|
60 |
"role": "system",
|
61 |
"content": (
|
62 |
+
"You are a friendly, helpful assistant."
|
63 |
+
" Use the following context to answer questions naturally and clearly."
|
64 |
+
" Be conversational and concise. Avoid saying you're using context."
|
65 |
+
" If unsure, say: 'Iβm not sure about that. Could you rephrase?'"
|
66 |
"\n\nContext:\n" + context
|
67 |
)
|
68 |
}
|
|
|
72 |
messages.append({"role": "user", "content": user})
|
73 |
messages.append({"role": "assistant", "content": assistant})
|
74 |
|
75 |
+
messages.append({"role": "user", "content": message + "\n\nKeep your reply short and natural."})
|
|
|
76 |
|
77 |
payload = {
|
78 |
"model": MODEL,
|
79 |
"messages": messages,
|
80 |
+
"max_tokens": 200,
|
81 |
}
|
82 |
|
83 |
try:
|
|
|
111 |
demo = gr.ChatInterface(
|
112 |
fn=chat_fn,
|
113 |
title="π¬ CODEX MIRXA KAMRAN",
|
114 |
+
description="Chat with our AI assistant based on internal knowledge. Short, natural and helpful answers!",
|
115 |
theme="soft"
|
116 |
)
|
117 |
|