from functools import lru_cache from pydantic_settings import BaseSettings, SettingsConfigDict class Settings(BaseSettings): model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore") # Vertex AI (primary) gcp_project: str = "" gcp_location: str = "us-central1" vertex_model: str = "gemini-2.0-flash-001" google_application_credentials: str = "" # Fallback: Groq (kept for local dev without gcloud) groq_api_key: str = "" groq_model: str = "llama-3.3-70b-versatile" cors_origins: str = "http://localhost:3000" log_level: str = "INFO" max_clauses_per_doc: int = 80 devil_advocate_min_severity: str = "medium" rag_top_k: int = 2 llm_concurrency: int = 2 @property def use_vertex(self) -> bool: return bool(self.gcp_project) @property def active_model(self) -> str: return self.vertex_model if self.use_vertex else self.groq_model @property def cors_origin_list(self) -> list[str]: return [origin.strip() for origin in self.cors_origins.split(",") if origin.strip()] @lru_cache(maxsize=1) def get_settings() -> Settings: return Settings()