File size: 498 Bytes
2585ab6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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

@app.post("/ask")
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))