Spaces:
Sleeping
Sleeping
Download routers/qa.py from vigneshwark/focusflow-api: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/spaces/vigneshwark/focusflow-api/resolve/main/routers/qa.py
- Command line
-
hf download hf://spaces/vigneshwark/focusflow-api/routers/qa.py
-
curl -L -o qa.py https://huggingface.co/spaces/vigneshwark/focusflow-api/resolve/main/routers/qa.py
1.01 kB
| from fastapi import APIRouter, HTTPException | |
| from pydantic import BaseModel | |
| from ml.embeddings import embed_single, load_embedding_model | |
| from ml.rag import retrieve | |
| from services.ollama_client import answer_question | |
| router = APIRouter() | |
| class QARequest(BaseModel): | |
| session_id: str | |
| question: str | |
| async def ask_question(req: QARequest): | |
| """Answer a user question using RAG over the live transcript.""" | |
| if not req.question.strip(): | |
| raise HTTPException(status_code=400, detail="Question cannot be empty") | |
| embedder = load_embedding_model() | |
| query_embedding = embed_single(req.question, embedder) | |
| context_chunks = retrieve(req.session_id, query_embedding, top_k=6) | |
| if not context_chunks: | |
| return { | |
| "answer": "I don't have enough context from the meeting to answer that yet.", | |
| "sources": [], | |
| } | |
| answer = answer_question(req.question, context_chunks) | |
| return {"answer": answer, "sources": context_chunks} | |