Spaces:
Sleeping
Sleeping
Download api.py from thaidinhz1/rag-vietnamese: direct link, hf CLI and curl.
- Browser
- Download file 924 Bytes
-
https://huggingface.co/spaces/thaidinhz1/rag-vietnamese/resolve/cc2a68207bc8f141e413b4b3a274745583b9f9f2/api.py
- Command line
-
hf download hf://spaces/thaidinhz1/rag-vietnamese@cc2a68207bc8f141e413b4b3a274745583b9f9f2/api.py
-
curl -L -o api.py https://huggingface.co/spaces/thaidinhz1/rag-vietnamese/resolve/cc2a68207bc8f141e413b4b3a274745583b9f9f2/api.py
924 Bytes
| from fastapi import FastAPI | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.responses import HTMLResponse | |
| from pydantic import BaseModel | |
| from src.rag import answer | |
| app = FastAPI(title="Vietnamese RAG API") | |
| class QueryRequest(BaseModel): | |
| question: str | |
| top_k: int = 5 | |
| class Source(BaseModel): | |
| source: str | |
| page: int | |
| rrf_score: float | |
| rerank_score: float | |
| class QueryResponse(BaseModel): | |
| answer: str | |
| sources: list[Source] | |
| def index(): | |
| with open("static/index.html", encoding="utf-8") as f: | |
| return f.read() | |
| def query(req: QueryRequest): | |
| result = answer(req.question, top_k=req.top_k) | |
| return QueryResponse( | |
| answer=result["answer"], | |
| sources=[Source(**s) for s in result["sources"]], | |
| ) | |
| def health(): | |
| return {"status": "ok"} |