""" Application configuration models. """ import os from pydantic import BaseModel from pydantic_settings import ( BaseSettings, PydanticBaseSettingsSource, YamlConfigSettingsSource, ) APP_PREFIX: str = os.getenv("01_APP_PREFIX", "01_") class Client(BaseModel): """ Client configuration model """ enabled: bool = False url: None | str = None platform: str = "auto" class LLM(BaseModel): """ LLM configuration model """ service: str = "litellm" model: str = "gpt-4" vision_enabled: bool = False functions_enabled: bool = False context_window: int = 2048 max_tokens: int = 4096 temperature: float = 0.8 class Local(BaseModel): """ Local configuration model """ enabled: bool = False tts_service: str = "piper" stt_service: str = "local-whisper" class Server(BaseModel): """ Server configuration model """ enabled: bool = False host: str = "0.0.0.0" port: int = 10001 class STT(BaseModel): """ Speech-to-text configuration model """ service: str = "openai" class TTS(BaseModel): """ Text-to-speech configuration model """ service: str = "openai" class Tunnel(BaseModel): """ Tunnel configuration model """ service: str = "ngrok" exposed: bool = False class Config(BaseSettings): """ Base configuration model """ client: Client = Client() llm: LLM = LLM() local: Local = Local() server: Server = Server() stt: STT = STT() tts: TTS = TTS() tunnel: Tunnel = Tunnel() @classmethod def settings_customise_sources( cls, settings_cls: type[BaseSettings], init_settings: PydanticBaseSettingsSource, env_settings: PydanticBaseSettingsSource, dotenv_settings: PydanticBaseSettingsSource, file_secret_settings: PydanticBaseSettingsSource, ) -> tuple[PydanticBaseSettingsSource, ...]: """ Modify the order of precedence for settings sources. """ return ( YamlConfigSettingsSource( settings_cls, yaml_file=os.getenv(f"{APP_PREFIX}CONFIG_FILE", "config.yaml"), ), )