ConverTA / config /settings.py
MikelWL's picture
Feat: persist sealed runs to SQLite
a7fd580
"""Centralized application settings loaded from environment variables.
Uses pydantic-settings so both backend and frontend can share defaults and
override them through a `.env` file or process environment variables.
"""
from functools import lru_cache
from typing import Optional
from pydantic_settings import BaseSettings, SettingsConfigDict
class APISettings(BaseSettings):
"""Configuration for the FastAPI backend."""
host: str = "0.0.0.0"
port: int = 8000
log_level: str = "INFO"
model_config = SettingsConfigDict(
env_prefix="API_",
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
)
class LLMSettings(BaseSettings):
"""Configuration for the language model backend."""
backend: str = "ollama"
host: str = "http://localhost:11434"
model: str = "llama3.2:latest"
timeout: int = 120
max_retries: int = 3
retry_delay: float = 1.0
api_key: Optional[str] = None
site_url: Optional[str] = None
app_name: Optional[str] = None
model_config = SettingsConfigDict(
env_prefix="LLM_",
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
)
class FrontendSettings(BaseSettings):
"""Configuration for the Gradio frontend."""
backend_base_url: str = "http://localhost:8000"
websocket_url: str = "ws://localhost:8000/ws/conversation"
model_config = SettingsConfigDict(
env_prefix="FRONTEND_",
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
)
class DBSettings(BaseSettings):
"""Configuration for persistent storage."""
path: str = ".localdata/converta.db"
model_config = SettingsConfigDict(
env_prefix="DB_",
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
)
class AppSettings(BaseSettings):
"""Aggregate configuration exposed to the application."""
api: APISettings = APISettings()
llm: LLMSettings = LLMSettings()
frontend: FrontendSettings = FrontendSettings()
db: DBSettings = DBSettings()
log_level: str = "INFO"
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
)
@lru_cache
def get_settings() -> AppSettings:
"""Return the singleton settings instance."""
return AppSettings()