mirxakamran893 commited on
Commit
96bb719
Β·
verified Β·
1 Parent(s): e43d7d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -11
app.py CHANGED
@@ -48,20 +48,21 @@ def chat_fn(message, history):
48
 
49
  context = get_context(message)
50
 
51
- # βœ… Allow fallback for greetings
52
  if not context.strip():
53
  if is_greeting(message):
54
- return "πŸ‘‹ Hello! How can I assist you today?"
55
- return "❌ I couldn’t find any relevant info to answer that. Please ask something else."
56
 
57
- # βœ… Construct message payload
58
  messages = [
59
  {
60
  "role": "system",
61
  "content": (
62
- "You are a precise, concise assistant. Use ONLY the provided context."
63
- " Respond in 1–2 short sentences maximum. Do not explain unless asked."
64
- " If unsure, say: 'I couldn’t find the answer based on available context.'"
 
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
- # βœ… Encourage brevity in user input
75
- messages.append({"role": "user", "content": message + "\n\nPlease answer briefly."})
76
 
77
  payload = {
78
  "model": MODEL,
79
  "messages": messages,
80
- "max_tokens": 150,
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="Ask anything related to our knowledge base. Short, fast and precise answers!",
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