grvelight commited on
Commit
b63e64d
Β·
verified Β·
1 Parent(s): 8424472

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +22 -9
api.py CHANGED
@@ -90,13 +90,13 @@ You are given retrieved research context. Use it to answer the question as fully
90
  - Mention journal names or PMIDs when available."""
91
 
92
  WEB_SYSTEM_PROMPT = """You are CovidKosha Assistant, an expert on COVID-19.
93
- You have been given live web-search results because the local research database did not contain
94
- a satisfactory answer to the user's question.
95
- - Summarise the most relevant findings from the search results clearly and concisely.
96
- - Cite sources using [1], [2] etc. from the provided web context.
97
- - If the CovidKosha website results are included, highlight those explicitly.
98
- - Be accurate; do not fabricate information not present in the search results.
99
- - Use bullet points where helpful."""
100
 
101
  # ─────────────────────── HELPERS ────────────────────────
102
  def retrieve(question: str, k: int = TOP_K):
@@ -350,11 +350,19 @@ def ask(req: QueryRequest):
350
  system_prompt = WEB_SYSTEM_PROMPT
351
  fallback_used = True
352
 
 
 
 
 
 
 
 
 
353
  response = groq_client.chat.completions.create(
354
  model=GROQ_MODEL,
355
  messages=[
356
  {"role": "system", "content": system_prompt},
357
- {"role": "user", "content": f"Research Context:\n{context}\n\nQuestion: {req.question}"}
358
  ],
359
  temperature=0.2,
360
  max_tokens=1024,
@@ -434,11 +442,16 @@ def ask_stream(req: QueryRequest):
434
  yield "FALLBACK:1\n" # signal to the frontend
435
  system_prompt = WEB_SYSTEM_PROMPT
436
 
 
 
 
 
 
437
  stream = groq_client.chat.completions.create(
438
  model=GROQ_MODEL,
439
  messages=[
440
  {"role": "system", "content": system_prompt},
441
- {"role": "user", "content": f"Research Context:\n{context}\n\nQuestion: {req.question}"}
442
  ],
443
  temperature=0.2,
444
  max_tokens=1024,
 
90
  - Mention journal names or PMIDs when available."""
91
 
92
  WEB_SYSTEM_PROMPT = """You are CovidKosha Assistant, an expert on COVID-19.
93
+ Answer the user's question using the provided web search results.
94
+ - Give a complete, confident answer β€” never say the topic is "not covered", "not in the context", or similar.
95
+ - Cite sources using [1], [2] etc. from the provided results.
96
+ - If CovidKosha website results are present, highlight those first.
97
+ - Be accurate; do not fabricate anything not in the search results.
98
+ - Use bullet points where helpful.
99
+ - Do NOT mention that you are using web search, a fallback, or any internal retrieval mechanism."""
100
 
101
  # ─────────────────────── HELPERS ────────────────────────
102
  def retrieve(question: str, k: int = TOP_K):
 
350
  system_prompt = WEB_SYSTEM_PROMPT
351
  fallback_used = True
352
 
353
+ # Avoid framing as "Research Context" during web fallback so the model
354
+ # won't hedge about coverage gaps.
355
+ user_msg = (
356
+ f"Web Search Results:\n{context}\n\nQuestion: {req.question}"
357
+ if fallback_used else
358
+ f"Research Context:\n{context}\n\nQuestion: {req.question}"
359
+ )
360
+
361
  response = groq_client.chat.completions.create(
362
  model=GROQ_MODEL,
363
  messages=[
364
  {"role": "system", "content": system_prompt},
365
+ {"role": "user", "content": user_msg}
366
  ],
367
  temperature=0.2,
368
  max_tokens=1024,
 
442
  yield "FALLBACK:1\n" # signal to the frontend
443
  system_prompt = WEB_SYSTEM_PROMPT
444
 
445
+ user_msg = (
446
+ f"Web Search Results:\n{context}\n\nQuestion: {req.question}"
447
+ if system_prompt is WEB_SYSTEM_PROMPT else
448
+ f"Research Context:\n{context}\n\nQuestion: {req.question}"
449
+ )
450
  stream = groq_client.chat.completions.create(
451
  model=GROQ_MODEL,
452
  messages=[
453
  {"role": "system", "content": system_prompt},
454
+ {"role": "user", "content": user_msg}
455
  ],
456
  temperature=0.2,
457
  max_tokens=1024,