Spaces:
Sleeping
Sleeping
| """FastAPI application entry point.""" | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from app.api import documents, chat, folders | |
| from app.database import init_db | |
| from app.config import get_settings | |
| from app.dependencies import get_embedder_port, get_vector_db_port | |
| import logging | |
| # Configure logging | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' | |
| ) | |
| logger = logging.getLogger(__name__) | |
| settings = get_settings() | |
| app = FastAPI( | |
| title="Ragora API", | |
| description="RAG-based document chat system", | |
| version="1.0.0" | |
| ) | |
| # CORS | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], # Configure for production | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Include routers | |
| app.include_router(documents.router) | |
| app.include_router(chat.router) | |
| app.include_router(folders.router) | |
| async def startup_event(): | |
| """Initialize on startup.""" | |
| logger.info("Starting Ragora API...") | |
| # Initialize database (optional) | |
| try: | |
| init_db() | |
| logger.info("Database initialized") | |
| except Exception as e: | |
| logger.warning(f"Database initialization skipped: {e}") | |
| # Initialize vector DB collection (optional) | |
| try: | |
| embedder = get_embedder_port() | |
| vector_db = get_vector_db_port() | |
| await vector_db.initialize_collection( | |
| settings.QDRANT_COLLECTION, | |
| embedder.get_dimension() | |
| ) | |
| logger.info("Vector DB initialized") | |
| except Exception as e: | |
| logger.warning(f"Vector DB initialization skipped: {e}") | |
| def health_check(): | |
| """Health check endpoint.""" | |
| return {"status": "healthy"} | |
| def root(): | |
| """Root endpoint.""" | |
| return { | |
| "message": "Ragora API", | |
| "version": "1.0.0", | |
| "docs": "/docs" | |
| } | |