Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI, HTTPException | |
| from pydantic import BaseModel | |
| import asyncio | |
| from rag_core import rag_chain | |
| app = FastAPI(title="RAG API") | |
| class QuestionRequest(BaseModel): | |
| question: str | |
| async def ask_question(payload: QuestionRequest): | |
| try: | |
| result = await asyncio.to_thread(rag_chain.invoke, payload.question) | |
| return {"answer": result} | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=str(e)) | |