Phase 28: P3 — Pydantic Settings, dependency-injector IoC, tenacity retry
- config.py: dataclasses → pydantic-settings BaseSettings (flat AppConfig, env vars auto-loaded from .env, type-safe validation) - api_client.py: HTTPAPIClient takes AppConfig directly (APIConfig removed); tenacity retry on 5 methods (reset/ingest/list/delete/feedback) — retries on 5xx + TransportError, 3 attempts, exponential backoff 1-8s - container.py: manual DI → dependency_injector DeclarativeContainer with providers.Singleton; Container() needs no args - app.py: container.X → container.X() calls, remove AppConfig import - requirements.txt: add pydantic-settings, tenacity, dependency-injector Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,19 +1,18 @@
|
||||
from dataclasses import dataclass, field
|
||||
import os
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
@dataclass
|
||||
class APIConfig:
|
||||
url: str = field(default_factory=lambda: os.getenv("YOULBOT_API_URL", "http://localhost:8000"))
|
||||
token: str = field(default_factory=lambda: os.getenv("YOULBOT_API_TOKEN", ""))
|
||||
timeout: int = 180
|
||||
|
||||
|
||||
@dataclass
|
||||
class AppConfig:
|
||||
api: APIConfig = field(default_factory=APIConfig)
|
||||
whisper_model_size: str = field(default_factory=lambda: os.getenv("WHISPER_MODEL_SIZE", "small"))
|
||||
tts_voice: str = field(default_factory=lambda: os.getenv("TTS_VOICE", "Yuna"))
|
||||
tts_edge_voice: str = field(default_factory=lambda: os.getenv("TTS_EDGE_VOICE", "ko-KR-SunHiNeural"))
|
||||
class AppConfig(BaseSettings):
|
||||
# API (env: YOULBOT_API_URL, YOULBOT_API_TOKEN, YOULBOT_API_TIMEOUT)
|
||||
youlbot_api_url: str = "http://localhost:8000"
|
||||
youlbot_api_token: str = ""
|
||||
youlbot_api_timeout: int = 180
|
||||
# STT/TTS (env: WHISPER_MODEL_SIZE, TTS_VOICE, TTS_EDGE_VOICE)
|
||||
whisper_model_size: str = "small"
|
||||
tts_voice: str = "Yuna"
|
||||
tts_edge_voice: str = "ko-KR-SunHiNeural"
|
||||
# 서버 / 로깅
|
||||
log_level: str = "INFO"
|
||||
server_host: str = "0.0.0.0"
|
||||
server_port: int = 7860
|
||||
|
||||
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
|
||||
|
||||
Reference in New Issue
Block a user