Files
smart-support/backend/app/config.py
Yaojia Wang f0699436c5 refactor: engineering improvements -- API versioning, structured logging, Alembic, error standardization, test coverage
- API versioning: all REST endpoints prefixed with /api/v1/
- Structured logging: replaced stdlib logging with structlog (console/JSON modes)
- Alembic migrations: versioned DB schema with initial migration
- Error standardization: global exception handlers for consistent envelope format
- Interrupt cleanup: asyncio background task for expired interrupt removal
- Integration tests: +30 tests (analytics, replay, openapi, error, session APIs)
- Frontend tests: +57 tests (all components, pages, useWebSocket hook)
- Backend: 557 tests, 89.75% coverage | Frontend: 80 tests, 16 test files
2026-04-06 23:19:29 +02:00

71 lines
2.1 KiB
Python

"""Centralized application configuration via pydantic-settings."""
from __future__ import annotations
from typing import Literal
from pydantic import model_validator
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
)
database_url: str
llm_provider: Literal["anthropic", "openai", "azure_openai", "google"] = "anthropic"
llm_model: str = "claude-sonnet-4-6"
session_ttl_minutes: int = 30
interrupt_ttl_minutes: int = 30
ws_host: str = "0.0.0.0"
ws_port: int = 8000
webhook_url: str = ""
webhook_timeout_seconds: int = 10
webhook_max_retries: int = 3
template_name: str = ""
log_format: str = "console" # "console" for dev, "json" for production
admin_api_key: str = ""
anthropic_api_key: str = ""
openai_api_key: str = ""
azure_openai_api_key: str = ""
azure_openai_endpoint: str = ""
azure_openai_api_version: str = "2024-12-01-preview"
azure_openai_deployment: str = ""
google_api_key: str = ""
@model_validator(mode="after")
def validate_provider_key(self) -> Settings:
key_map = {
"anthropic": self.anthropic_api_key,
"openai": self.openai_api_key,
"azure_openai": self.azure_openai_api_key,
"google": self.google_api_key,
}
key = key_map.get(self.llm_provider, "")
if not key:
raise ValueError(
f"API key for provider '{self.llm_provider}' is required. "
f"Set the corresponding environment variable."
)
if self.llm_provider == "azure_openai":
if not self.azure_openai_endpoint:
raise ValueError(
"AZURE_OPENAI_ENDPOINT is required for azure_openai provider."
)
if not self.azure_openai_deployment:
raise ValueError(
"AZURE_OPENAI_DEPLOYMENT is required for azure_openai provider."
)
return self