Spaces:
Runtime error
Runtime error
Download app/api/query.py from Abdullahcoder54/Hackaton1_BOOK_chatbot: direct link, hf CLI and curl.
- Browser
- Download file 758 Bytes
-
https://huggingface.co/spaces/Abdullahcoder54/Hackaton1_BOOK_chatbot/resolve/main/app/api/query.py
- Command line
-
hf download hf://spaces/Abdullahcoder54/Hackaton1_BOOK_chatbot/app/api/query.py
-
curl -L -o query.py https://huggingface.co/spaces/Abdullahcoder54/Hackaton1_BOOK_chatbot/resolve/main/app/api/query.py
758 Bytes
| from fastapi import APIRouter, HTTPException | |
| from ..schemas import QueryRequest, QueryResponse | |
| from ..services.rag_service import get_rag_response | |
| router = APIRouter() | |
| async def query_chatbot(request: QueryRequest): | |
| try: | |
| response_text, sources = await get_rag_response(request.message, request.selected_text) | |
| return QueryResponse(response=response_text, sources=sources) | |
| except Exception as e: | |
| # Log the full error to the backend console for debugging | |
| print(f"An unexpected error occurred: {e}") | |
| # Return a generic but informative error to the frontend | |
| raise HTTPException(status_code=500, detail=f"An internal error occurred in the backend: {e}") |