from fastapi import APIRouter, HTTPException from pydantic import BaseModel from dependencies import ChatbotDep, CurrentUserIdDep router = APIRouter(tags=["query"]) class ChatRequest(BaseModel): chat_id: str question: str allow_augmentation: bool = False use_web_search: bool = False @router.post("/response") def response(request_body: ChatRequest, chatbot: ChatbotDep, user_id: CurrentUserIdDep): try: answer, suggested_questions = chatbot.response( request_body.question, request_body.chat_id, user_id, allow_augmentation=request_body.allow_augmentation, use_web_search=request_body.use_web_search, ) return { "answer": answer, "suggested_questions": suggested_questions, } except KeyError: raise HTTPException(status_code=404, detail="Chat ID not found") except Exception: raise HTTPException(status_code=500, detail="GPU error, try after some time...")