Spaces:
Runtime error
Runtime error
File size: 1,024 Bytes
c5cf697 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | 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...")
|