Update api.py
Browse files
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 |
-
|
| 94 |
-
a
|
| 95 |
-
-
|
| 96 |
-
-
|
| 97 |
-
-
|
| 98 |
-
-
|
| 99 |
-
-
|
| 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":
|
| 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":
|
| 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,
|