grvelight commited on
Commit
21023ea
Β·
verified Β·
1 Parent(s): 3030eb2

Update api.py

Browse files
Files changed (1) hide show
  1. api.py +11 -4
api.py CHANGED
@@ -13,7 +13,8 @@ import numpy as np
13
  import faiss
14
  from fastapi import FastAPI, HTTPException
15
  from fastapi.middleware.cors import CORSMiddleware
16
- from fastapi.responses import StreamingResponse
 
17
  from pydantic import BaseModel
18
  from sentence_transformers import SentenceTransformer
19
  from groq import Groq
@@ -24,7 +25,7 @@ if not GROQ_API_KEY:
24
  raise RuntimeError("❌ GROQ_API_KEY not set β€” add it to HF Space secrets")
25
 
26
  EMBED_MODEL = "all-MiniLM-L6-v2"
27
- GROQ_MODEL = "llama-3.3-70b-versatile"
28
  TOP_K = 5
29
 
30
  logging.basicConfig(level=logging.INFO)
@@ -72,9 +73,10 @@ class QueryRequest(BaseModel):
72
 
73
  # ─────────────────────── HELPERS ────────────────────────
74
  SYSTEM_PROMPT = """You are CovidKosha Assistant, an expert on COVID-19 research.
75
- Answer questions using ONLY the retrieved research context provided.
 
76
  - Cite source numbers [1], [2] etc. from the context.
77
- - If the context doesn't fully cover the question, say so honestly.
78
  - Be concise and accurate. Use bullet points where helpful.
79
  - Mention journal names or PMIDs when available."""
80
 
@@ -121,6 +123,11 @@ def build_context(results):
121
 
122
  # ─────────────────────── ROUTES ─────────────────────────
123
 
 
 
 
 
 
124
  @app.get("/health")
125
  def health():
126
  return {"status": "ok", "chunks": faiss_index.ntotal}
 
13
  import faiss
14
  from fastapi import FastAPI, HTTPException
15
  from fastapi.middleware.cors import CORSMiddleware
16
+ from fastapi.responses import StreamingResponse, HTMLResponse
17
+ from fastapi.staticfiles import StaticFiles
18
  from pydantic import BaseModel
19
  from sentence_transformers import SentenceTransformer
20
  from groq import Groq
 
25
  raise RuntimeError("❌ GROQ_API_KEY not set β€” add it to HF Space secrets")
26
 
27
  EMBED_MODEL = "all-MiniLM-L6-v2"
28
+ GROQ_MODEL = "llama-3.3-70b-versatile"
29
  TOP_K = 5
30
 
31
  logging.basicConfig(level=logging.INFO)
 
73
 
74
  # ─────────────────────── HELPERS ────────────────────────
75
  SYSTEM_PROMPT = """You are CovidKosha Assistant, an expert on COVID-19 research.
76
+ You are given retrieved research context. Use it to answer the question as fully as possible.
77
+ - ALWAYS provide a useful answer based on whatever context is available β€” never return only a disclaimer.
78
  - Cite source numbers [1], [2] etc. from the context.
79
+ - If the context only partially covers the question, answer what you can from it, then briefly note what is not covered.
80
  - Be concise and accurate. Use bullet points where helpful.
81
  - Mention journal names or PMIDs when available."""
82
 
 
123
 
124
  # ─────────────────────── ROUTES ─────────────────────────
125
 
126
+ @app.get("/", response_class=HTMLResponse)
127
+ def root():
128
+ with open(os.path.join(BASE_DIR, "index.html"), encoding="utf-8") as f:
129
+ return f.read()
130
+
131
  @app.get("/health")
132
  def health():
133
  return {"status": "ok", "chunks": faiss_index.ntotal}