hgzero/ai-python/app/config.py
Minseo-Jo c664116cd2 AI 제안사항 SSE 스트리밍 기능 구현 및 CORS 문제 해결
주요 변경사항:
- Event Hub 리스너를 Python AI Service에 통합하여 STT 텍스트 실시간 수신
- LocalDateTime 배열 형식을 Unix timestamp로 변환하는 로직 추가
- SSE 응답에 CORS 헤더 명시적 추가 (localhost:8888 허용)
- SSE Keep-alive를 위한 ping 이벤트 추가 (5초 주기)
- Redis 데이터 정리 스크립트 추가
- 분석 임계값을 MVP 수준으로 조정 (3개 세그먼트 = 약 15-30초)
- 프론트엔드 SSE 연동 가이드 문서 작성
- 프론트엔드에 ping 이벤트 핸들러 추가 및 에러 핸들링 개선

기술적 개선사항:
- EventSourceResponse에 Access-Control-Allow-Origin 헤더 추가
- timestamp 변환 로직으로 Java-Python 호환성 해결
- Redis 저장 오류 로깅 강화
- SSE generator에 주기적 heartbeat 전송으로 연결 유지

문서:
- develop/dev/ai-frontend-integration-guide.md: 프론트엔드 개발자를 위한 상세 연동 가이드

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-29 17:20:10 +09:00

58 lines
1.7 KiB
Python

"""환경 설정"""
from pydantic_settings import BaseSettings
from functools import lru_cache
from typing import List
class Settings(BaseSettings):
"""환경 설정 클래스"""
# 서버 설정
app_name: str = "AI Service (Python)"
host: str = "0.0.0.0"
port: int = 8087 # feature/stt-ai 브랜치 AI Service(8086)와 충돌 방지
# Claude API
claude_api_key: str = "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"
claude_model: str = "claude-3-5-sonnet-20240620"
claude_max_tokens: int = 250000
claude_temperature: float = 0.7
# Redis
redis_host: str = "20.249.177.114"
redis_port: int = 6379
redis_password: str = ""
redis_db: int = 4
# Azure Event Hub
eventhub_connection_string: str = "Endpoint=sb://hgzero-eventhub-ns.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=VUqZ9vFgu35E3c6RiUzoOGVUP8IZpFvlV+AEhC6sUpo="
eventhub_name: str = "hgzero-eventhub-name"
eventhub_consumer_group: str = "ai-transcript-group"
# CORS
cors_origins: List[str] = [
"http://localhost:8888",
"http://localhost:8080",
"http://localhost:3000",
"http://127.0.0.1:8888",
"http://127.0.0.1:8080",
"http://127.0.0.1:3000"
]
# 로깅
log_level: str = "INFO"
# 분석 임계값 (MVP 수준)
min_segments_for_analysis: int = 3 # 3개 세그먼트 = 약 15-30초 분량의 대화
text_retention_seconds: int = 300 # 5분
class Config:
env_file = ".env"
case_sensitive = False
@lru_cache()
def get_settings() -> Settings:
"""싱글톤 설정 인스턴스"""
return Settings()