Spaces:
Runtime error
Runtime error
Download src/main.py from abdullah9873/backend-rag-chatbot-v3: direct link, hf CLI and curl.
- Browser
- Download file 1.63 kB
-
https://huggingface.co/spaces/abdullah9873/backend-rag-chatbot-v3/resolve/main/src/main.py
- Command line
-
hf download hf://spaces/abdullah9873/backend-rag-chatbot-v3/src/main.py
-
curl -L -o main.py https://huggingface.co/spaces/abdullah9873/backend-rag-chatbot-v3/resolve/main/src/main.py
1.63 kB
| from contextlib import asynccontextmanager | |
| from fastapi import FastAPI, Request, status | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.responses import JSONResponse | |
| from .db_init import main as init_database | |
| from .api import auth_test, tasks | |
| from .api.routes import categories, chat | |
| from .core.exceptions import AgentError, ToolExecutionError, MCPError | |
| async def lifespan(app: FastAPI): | |
| init_database() | |
| yield | |
| app = FastAPI(lifespan=lifespan) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| app.include_router(auth_test.router, prefix="/api") | |
| app.include_router(tasks.router, prefix="/api") | |
| app.include_router(categories.router, prefix="/api/categories", tags=["categories"]) | |
| app.include_router(chat.router) | |
| def read_root(): | |
| return {"message": "Hello World"} | |
| async def agent_error_handler(request: Request, exc: AgentError): | |
| return JSONResponse( | |
| status_code=exc.status_code, | |
| content={"message": exc.detail}, | |
| ) | |
| async def tool_execution_error_handler(request: Request, exc: ToolExecutionError): | |
| return JSONResponse( | |
| status_code=exc.status_code, | |
| content={"message": exc.detail}, | |
| ) | |
| async def mcp_error_handler(request: Request, exc: MCPError): | |
| return JSONResponse( | |
| status_code=exc.status_code, | |
| content={"message": exc.detail}, | |
| ) | |