Spaces:
Runtime error
Runtime error
Download routes/query.py from cuiconnect/backend: direct link, hf CLI and curl.
- Browser
- Download file 1.02 kB
-
https://huggingface.co/spaces/cuiconnect/backend/resolve/main/routes/query.py
- Command line
-
hf download hf://spaces/cuiconnect/backend/routes/query.py
-
curl -L -o query.py https://huggingface.co/spaces/cuiconnect/backend/resolve/main/routes/query.py
1.02 kB
| 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 | |
| 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...") | |