replyflow-rag / api /routes /query.py
Qurrah's picture
ADD: implement rate limit exception handler in errors.py
ce912f9
Raw History Blame Contribute Delete
953 Bytes
# api/routes/query.py
import logging
from fastapi import APIRouter, Security
from api.schemas import QueryRequest, QueryResponse
from core.config import query_executor
from core.executor import run_blocking
from core.security import verify_api_key
from services.query_service import answer_query_request
logger = logging.getLogger(__name__)
router = APIRouter(tags=["query"])
@router.get("/health")
async def health():
return {"status": "ok"}
@router.post("/query", response_model=QueryResponse)
async def query(req: QueryRequest, _: str = Security(verify_api_key)):
reply = await run_blocking(
query_executor,
answer_query_request,
query=req.query,
channel=req.channel,
channel_identifier=req.channel_identifier,
external_id=req.external_id,
commenter_handle=req.commenter_handle,
post_caption=req.post_caption,
)
return QueryResponse(answer=reply, query=req.query)