"""AI Service - FastAPI 애플리케이션""" import logging import uvicorn from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from contextlib import asynccontextmanager from app.config import get_settings from app.api.v1 import suggestions # 로깅 설정 logging.basicConfig( level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s' ) logger = logging.getLogger(__name__) settings = get_settings() @asynccontextmanager async def lifespan(app: FastAPI): """애플리케이션 생명주기 관리""" logger.info("=" * 60) logger.info(f"AI Service (Python) 시작 - Port: {settings.port}") logger.info(f"Claude Model: {settings.claude_model}") logger.info(f"Redis: {settings.redis_host}:{settings.redis_port}") logger.info("=" * 60) # TODO: Event Hub 리스너 시작 (별도 백그라운드 태스크) # asyncio.create_task(start_eventhub_listener()) yield logger.info("AI Service 종료") # FastAPI 애플리케이션 app = FastAPI( title=settings.app_name, version="1.0.0", description="실시간 AI 제안사항 서비스 (Python)", lifespan=lifespan ) # CORS 설정 app.add_middleware( CORSMiddleware, allow_origins=settings.cors_origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # 라우터 등록 app.include_router( suggestions.router, prefix="/api/v1/ai/suggestions", tags=["AI Suggestions"] ) @app.get("/") async def root(): """루트 엔드포인트""" return { "service": settings.app_name, "version": "1.0.0", "status": "running", "endpoints": { "test": "/api/v1/ai/suggestions/test", "stream": "/api/v1/ai/suggestions/meetings/{meeting_id}/stream" } } @app.get("/health") async def health_check(): """헬스 체크""" return { "status": "healthy", "service": settings.app_name } if __name__ == "__main__": uvicorn.run( "main:app", host=settings.host, port=settings.port, reload=True, # 개발 모드 log_level=settings.log_level.lower() )