hgzero/ai-python/main.py
Minseo-Jo 032842cf53 Feat: AI 서비스 및 STT 서비스 기능 개선
- AI 서비스: Redis 캐싱 및 EventHub 통합 개선
- STT 서비스: 오디오 버퍼링 및 변환 기능 추가
- 설정 파일 업데이트

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-30 15:24:13 +09:00

80 lines
2.0 KiB
Python

"""AI Service FastAPI Application"""
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.config import get_settings
from app.api.v1 import router as api_v1_router
from app.services.eventhub_service import start_eventhub_listener
import logging
import asyncio
# 로깅 설정
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
# Settings
settings = get_settings()
# FastAPI 앱 생성
app = FastAPI(
title=settings.app_name,
description="AI-powered meeting minutes analysis service",
version="1.0.0",
docs_url="/api/docs",
redoc_url="/api/redoc",
openapi_url="/api/openapi.json"
)
# CORS 미들웨어 설정 (SSE 지원)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # 개발 환경에서는 모든 origin 허용
allow_credentials=True,
allow_methods=["GET", "POST", "OPTIONS"],
allow_headers=[
"Authorization",
"Content-Type",
"X-Requested-With",
"Accept",
"Origin",
"Access-Control-Request-Method",
"Access-Control-Request-Headers",
"Cache-Control",
"X-Accel-Buffering"
],
expose_headers=["*"],
)
# API 라우터 등록
app.include_router(api_v1_router, prefix="/api")
# Event Hub 리스너 백그라운드 태스크
@app.on_event("startup")
async def startup_event():
"""애플리케이션 시작 시 Event Hub 리스너 시작"""
logger.info("애플리케이션 시작 - Event Hub 리스너 백그라운드 실행")
asyncio.create_task(start_eventhub_listener())
@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()
)