Download scripts/smoke_qa.py from minhbe65/RAG-api: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/minhbe65/RAG-api/resolve/main/scripts/smoke_qa.py
- Command line
-
hf download hf://spaces/minhbe65/RAG-api/scripts/smoke_qa.py
-
curl -L -o smoke_qa.py https://huggingface.co/spaces/minhbe65/RAG-api/resolve/main/scripts/smoke_qa.py
1.13 kB
| """Khói: tìm kiếm + hỏi đáp có trích dẫn trên dữ liệu đã nạp.""" | |
| from app.agent.qa import answer_with_citations | |
| from app.db.base import SessionLocal | |
| from app.rag.search import search_nodes | |
| QUESTIONS = [ | |
| "Thời gian thử việc tối đa là bao lâu?", | |
| "Thời giờ làm việc bình thường trong một ngày tối đa là bao nhiêu giờ?", | |
| "Tuổi nghỉ hưu của người lao động là bao nhiêu?", | |
| ] | |
| db = SessionLocal() | |
| for q in QUESTIONS: | |
| print("\n### SEARCH:", q) | |
| for h in search_nodes(db, q, top_k=3): | |
| print(f" {h['display']} | {round(h['score'],3)} | {h['text'][:80]}") | |
| db.close() | |
| print("\n\n===== CITED QA =====") | |
| for q in QUESTIONS[:2]: | |
| print("\n### Q:", q) | |
| answer = "" | |
| cites = [] | |
| for event, data in answer_with_citations(q): | |
| if event == "token": | |
| answer += data["text"] | |
| elif event == "citation": | |
| cites.append(f"[{data['n']}] {data['display']}") | |
| elif event == "step": | |
| print(" (", data["label"], ")") | |
| print("A:", answer.strip()[:400]) | |
| print("Trích dẫn:", cites) | |