Team Ai
Apppublic

kernelmind/Resume-Screener-API

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
config.py97 linesDownload Raw Back to core
1"""2Configuration management using pydantic-settings.3 4Why pydantic-settings instead of raw os.environ?5- Type validation at startup (fail fast, not at runtime)6- IDE autocomplete for config values7- Automatic .env file loading without python-dotenv boilerplate8"""9 10from functools import lru_cache11from pathlib import Path12from typing import Annotated13 14from pydantic import Field15from pydantic_settings import BaseSettings, SettingsConfigDict16 17 18class Settings(BaseSettings):19    """20    Application settings loaded from environment variables.21    22    All settings can be overridden via .env file or environment variables.23    Environment variables take precedence over .env file values.24    """25    26    model_config = SettingsConfigDict(27        env_file=".env",28        env_file_encoding="utf-8",29        case_sensitive=False,30        extra="ignore",  # Don't crash on unknown env vars31    )32    33    # API Keys34    gemini_api_key: Annotated[35        str,36        Field(description="Google Gemini API key from AI Studio")37    ]38    39    # Storage40    chroma_persist_dir: Annotated[41        Path,42        Field(43            default=Path("./chroma_db"),44            description="Directory for ChromaDB persistent storage"45        )46    ]47    48    # Rate Limiting - Keep it reasonable to prevent abuse49    rate_limit_per_minute: Annotated[50        int,51        Field(52            default=10,53            ge=1,54            le=100,55            description="Max API requests per minute per IP"56        )57    ]58    59    # Embedding Model60    embedding_model: Annotated[61        str,62        Field(63            default="sentence-transformers/all-MiniLM-L6-v2",64            description="HuggingFace model ID for embeddings"65        )66    ]67    68    # Logging69    log_level: Annotated[70        str,71        Field(72            default="INFO",73            pattern="^(DEBUG|INFO|WARNING|ERROR|CRITICAL)$",74            description="Logging verbosity level"75        )76    ]77    78    # Gemini Model - 2.0 Flash is fast and widely available79    gemini_model: Annotated[80        str,81        Field(82            default="gemini-1.5-flash",83            description="Gemini model to use for text extraction"84        )85    ]86 87 88@lru_cache89def get_settings() -> Settings:90    """91    Cached settings instance.92    93    Using lru_cache here because settings should be loaded once at startup,94    not re-parsed on every request. This is a common pattern in FastAPI apps.95    """96    return Settings()97