/
gnomdeployer
/
VUZPlus
Обзор
Документация
Войти
/
gnomdeployer
/
VUZPlus
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
master
llm_api/main.py
83 строки
2 KB
daniil
univer
18 апр 2025, 22:15
18 апр 2025, 22:15
5447de5
Код
Авторство
О чём код?
import logging import sys from fastapi import FastAPI, HTTPException, Request from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse import uvicorn import traceback from routers import analysis, matching from db.postgres import initialize_db from config import settings # Configure logging logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', handlers=[ logging.StreamHandler(sys.stdout), #logging.FileHandler('app.log') ] ) logger = logging.getLogger(__name__) # Create FastAPI app app = FastAPI( title="Academic Analysis and Matching Service", description="API for analyzing student work and matching students to academic directions", version="1.0.0" ) # Add CORS middleware app.add_middleware( CORSMiddleware, allow_origins=["*"], # In production, replace with specific origins allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # Global exception handler @app.exception_handler(Exception) async def global_exception_handler(request: Request, exc: Exception): logger.error(f"Unhandled exception: {exc}") logger.error(traceback.format_exc()) return JSONResponse( status_code=500, content={"error": "Internal server error", "detail": str(exc)} ) # Include routers app.include_router(analysis.router) app.include_router(matching.router) @app.get("/") async def root(): """Root endpoint - health check""" return {"message": "Academic Analysis and Matching Service is running"} @app.get("/health") async def health_check(): """Health check endpoint""" return {"status": "healthy"} # Startup event @app.on_event("startup") async def startup_event(): """Initialize components on startup""" try: # Initialize database tables initialize_db() logger.info("Application started successfully") except Exception as e: logger.error(f"Error during startup: {e}") logger.error(traceback.format_exc()) # Run the application if __name__ == "__main__": try: uvicorn.run("main:app", host="0.0.0.0", port=8888, reload=True) except Exception as e: logger.error(f"Error running application: {e}") logger.error(traceback.format_exc())