from functools import lru_cache from pathlib import Path from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): model_config = SettingsConfigDict(env_file=".env", extra="ignore") database_url: str = "postgresql+psycopg://gost:gost@localhost:5432/gost" api_token: str = "changeme" # legacy bearer; also JWT secret / admin password fallback admin_username: str = "admin" admin_password: str = "" # empty → use api_token jwt_secret: str = "" # empty → use api_token jwt_expire_hours: int = 72 data_dir: str = "./data" font_path: str = str(Path(__file__).resolve().parents[2] / "fonts" / "GOST_A.TTF") openrouter_base_url: str = "https://openrouter.ai/api/v1" openrouter_api_key: str = "" openrouter_model: str = "deepseek/deepseek-chat" # SOCKS5 proxy for OpenRouter, e.g. socks5://user:pass@host:1080 openrouter_proxy: str = "" llm_max_context_rows: int = 80 # Soft context window for the usage meter (tokens). Trim history if exceeded. llm_context_limit: int = 64000 cors_origins: str = "*" @property def cors_origin_list(self) -> list[str]: if self.cors_origins.strip() == "*": return ["*"] return [o.strip() for o in self.cors_origins.split(",") if o.strip()] @lru_cache def get_settings() -> Settings: return Settings()