mirror of
https://github.com/hwanny1128/HGZero.git
synced 2025-12-06 07:56:24 +00:00
주요 변경사항: - AI 서비스 Java → Python (FastAPI) 완전 마이그레이션 - 포트 변경: 8083 → 8086 - SSE 스트리밍 기능 구현 및 테스트 완료 - Claude API 연동 (claude-3-5-sonnet-20241022) - Redis 슬라이딩 윈도우 방식 텍스트 축적 - Azure Event Hub 연동 준비 (STT 텍스트 수신) 프론트엔드 연동 지원: - API 연동 가이드 업데이트 (Python 버전 반영) - Mock 데이터 개발 가이드 신규 작성 - STT 개발 완료 전까지 Mock 데이터로 UI 개발 가능 기술 스택: - Python 3.13 - FastAPI 0.104.1 - Anthropic Claude API 0.42.0 - Redis (asyncio) 5.0.1 - Azure Event Hub 5.11.4 - Pydantic 2.10.5 테스트 결과: - ✅ 서비스 시작 정상 - ✅ 헬스 체크 성공 - ✅ SSE 스트리밍 동작 확인 - ✅ Redis 연결 정상 다음 단계: - STT (Azure Speech) 서비스 연동 개발 - Event Hub를 통한 실시간 텍스트 수신 - E2E 통합 테스트 (STT → AI → Frontend) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
94 lines
2.1 KiB
Python
94 lines
2.1 KiB
Python
"""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()
|
|
)
|