44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
from functools import lru_cache
|
|
from typing import ClassVar
|
|
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""Runtime configuration.
|
|
|
|
Values come from `DASH_`-prefixed environment variables or a local
|
|
`.env` file; unknown variables are ignored. See `.env.example` for the
|
|
full list of knobs.
|
|
"""
|
|
|
|
model_config: ClassVar[SettingsConfigDict] = SettingsConfigDict(env_prefix="DASH_", env_file=".env", extra="ignore")
|
|
|
|
host: str = "127.0.0.1"
|
|
port: int = 8501
|
|
sample_interval: float = 2.0
|
|
retention_minutes: int = 60
|
|
chart_max_points: int = 200
|
|
|
|
llama_base_url: str = "http://127.0.0.1:8080"
|
|
llama_api_key: str = ""
|
|
llama_timeout: float = 4.0
|
|
|
|
@property
|
|
def history_maxlen(self) -> int:
|
|
"""Ring buffer size for `retention_minutes` of samples (min 10).
|
|
|
|
Returns:
|
|
`retention_minutes * 60 / sample_interval`, at least 10.
|
|
"""
|
|
return max(10, int(self.retention_minutes * 60 / self.sample_interval))
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
"""Return the process-wide cached Settings instance.
|
|
|
|
Returns:
|
|
A Settings instance, parsed once and reused for the process lifetime.
|
|
"""
|
|
return Settings()
|