mirxakamran893 commited on
Commit
be128ec
·
verified ·
1 Parent(s): 01817d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -44,14 +44,17 @@ def chat_fn(message, history):
44
 
45
  context = get_context(message)
46
 
47
- # No valid context? Respond with fallback message
48
  if not context.strip():
49
  return "❌ Sorry, I can't answer that."
50
 
51
  messages = [
52
  {
53
  "role": "system",
54
- "content": "You are a helpful assistant. Only use the context below to answer. If you can't find an answer in it, reply: 'Sorry, I can't answer that.'\n\nContext:\n" + context
 
 
 
 
55
  }
56
  ]
57
 
@@ -61,7 +64,11 @@ def chat_fn(message, history):
61
 
62
  messages.append({"role": "user", "content": message})
63
 
64
- payload = {"model": MODEL, "messages": messages}
 
 
 
 
65
 
66
  try:
67
  response = requests.post("https://openrouter.ai/api/v1/chat/completions", headers=headers, json=payload)
 
44
 
45
  context = get_context(message)
46
 
 
47
  if not context.strip():
48
  return "❌ Sorry, I can't answer that."
49
 
50
  messages = [
51
  {
52
  "role": "system",
53
+ "content": (
54
+ "You are a concise and helpful assistant. Use only the context below to answer. "
55
+ "Respond clearly and briefly. Avoid unnecessary details. If the context doesn't contain the answer, reply: "
56
+ "'Sorry, I can't answer that.'\n\nContext:\n" + context
57
+ )
58
  }
59
  ]
60
 
 
64
 
65
  messages.append({"role": "user", "content": message})
66
 
67
+ payload = {
68
+ "model": MODEL,
69
+ "messages": messages,
70
+ "max_tokens": 200 # Optional: limit response length
71
+ }
72
 
73
  try:
74
  response = requests.post("https://openrouter.ai/api/v1/chat/completions", headers=headers, json=payload)