Spaces:
Sleeping
Sleeping
| """FastAPI application main file.""" | |
| import sys | |
| from pathlib import Path | |
| # Add parent directory to path to allow imports from src | |
| parent_dir = Path(__file__).parent.parent | |
| if str(parent_dir) not in sys.path: | |
| sys.path.insert(0, str(parent_dir)) | |
| import logging | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from src.core.config import get_settings | |
| from api.routes import router | |
| # Configure logging | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", | |
| ) | |
| logger = logging.getLogger(__name__) | |
| # Initialize FastAPI app | |
| app = FastAPI( | |
| title="Agentic RAG System API", | |
| description="Production-ready Agentic RAG system with multiple agents and MCP servers", | |
| version="1.0.0", | |
| ) | |
| # Configure CORS | |
| settings = get_settings() | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], # In production, specify allowed origins | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Include routes | |
| app.include_router(router) | |
| async def startup_event(): | |
| """Initialize components on startup.""" | |
| logger.info("Starting Agentic RAG System API") | |
| logger.info(f"API running on {settings.api_host}:{settings.api_port}") | |
| async def shutdown_event(): | |
| """Cleanup on shutdown.""" | |
| logger.info("Shutting down Agentic RAG System API") | |
| if __name__ == "__main__": | |
| import uvicorn | |
| uvicorn.run( | |
| "main:app", | |
| host=settings.api_host, | |
| port=settings.api_port, | |
| reload=settings.api_debug, | |
| ) | |