hgzero/ai-python/main.py
Minseo-Jo 2c3bc432b3 STT 서비스 음성 인식 및 AI 제안사항 표시 기능 구현
- PCM 16kHz 포맷 지원으로 Azure Speech 인식 성공
- WebSocket 실시간 전송 기능 추가
- DB 저장 로직 제거 (AI 서비스에서 제안사항 저장)
- AI SSE 기반 제안사항 표시 테스트 페이지 추가

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-28 10:12:55 +09:00

97 lines
2.4 KiB
Python

"""AI Service - FastAPI 애플리케이션"""
import logging
import asyncio
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
from app.services.eventhub_service import start_eventhub_listener
# 로깅 설정
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)
# Event Hub 리스너 시작 (백그라운드 태스크)
logger.info("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 설정 (개발 환경: 모든 origin 허용)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # 개발 환경에서 모든 origin 허용
allow_credentials=False, # allow_origins=["*"]일 때는 False여야 함
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()
)