from pydantic_settings import BaseSettings from typing import Optional, Dict, Any, List import os from functools import lru_cache class Settings(BaseSettings): """ Application settings loaded from environment variables or .env file """ # API keys GROQ_API_KEY: str # LLM settings MODEL_NAME: str = "qwen-2.5-32b" MAX_TOKENS: int = 2048 TEMPERATURE: float = 0.5 FALLBACK_TEMPERATURE: float = 0.7 GRAMMAR_CORRECTION_TEMPERATURE: float = 0.3 # SQLite settings SQLITE_DB_PATH: str = os.environ.get("SQLITE_DB_PATH", "profiles.db") # Service settings API_HOST: str = os.environ.get("API_HOST", "0.0.0.0") # Changed from localhost to 0.0.0.0 API_PORT: int = int(os.environ.get("API_PORT", "8000")) # External-facing URL for API (this should be set in production) EXTERNAL_API_URL: str = os.environ.get("EXTERNAL_API_URL", "") # API URL - will use external URL if provided, otherwise build from host/port API_URL: str = os.environ.get("API_URL", EXTERNAL_API_URL or f"http://{API_HOST}:{API_PORT}") # Allowed origins for CORS ALLOWED_ORIGINS: List[str] = ["*"] # Streamlit settings STREAMLIT_PORT: int = int(os.environ.get("STREAMLIT_SERVER_PORT", "8501")) # Application settings CACHE_SIZE: int = 100 CHUNK_SIZE: int = 1000 DEBUG: bool = os.environ.get("DEBUG", "").lower() == "true" # File settings TEMP_FILE_DIR: str = os.environ.get("TEMP_FILE_DIR", "./") class Config: env_file = ".env" case_sensitive = True @lru_cache() def get_settings() -> Settings: """ Get cached settings instance """ return Settings()