| from fastapi import FastAPI, HTTPException | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.responses import FileResponse | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from dotenv import load_dotenv | |
| from api.chat import chat_router | |
| load_dotenv() | |
| app = FastAPI( | |
| title="Chat Assistant API", | |
| description="FastAPI backend for chat assistant with LiteLLM and Gemini", | |
| version="1.0.0" | |
| ) | |
| # CORS middleware for frontend integration | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], # Configure this properly for production | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Include routers | |
| app.include_router(chat_router, prefix="/api") | |
| # Mount static files for the frontend | |
| app.mount("/static", StaticFiles(directory="static"), name="static") | |
| async def root(): | |
| return FileResponse("static/index.html") | |
| async def health_check(): | |
| return {"status": "healthy"} |