| """ |
| Application configuration using Pydantic Settings. |
| Loads from environment variables and .env file. |
| """ |
|
|
| from functools import lru_cache |
| from typing import Optional |
|
|
| from pydantic_settings import BaseSettings, SettingsConfigDict |
|
|
|
|
| class Settings(BaseSettings): |
| """Application settings loaded from environment variables.""" |
|
|
| model_config = SettingsConfigDict( |
| env_file=".env", |
| env_file_encoding="utf-8", |
| case_sensitive=False, |
| ) |
|
|
| |
| database_url: str = "" |
|
|
| |
| app_env: str = "production" |
| debug: bool = False |
| app_title: str = "Fair Dispatch System" |
| app_version: str = "1.0.0" |
| api_prefix: str = "/api/v1" |
|
|
| |
| cors_origins: str = "https://fairrelay.vercel.app,https://fairrelay-dashboard.vercel.app" |
|
|
| |
| workload_weight_a: float = 1.0 |
| workload_weight_b: float = 0.5 |
| workload_weight_c: float = 10.0 |
| workload_weight_d: float = 0.2 |
|
|
| |
| target_packages_per_route: int = 20 |
|
|
| |
| difficulty_weight_per_kg: float = 0.01 |
| difficulty_weight_per_stop: float = 0.1 |
| difficulty_base: float = 1.0 |
|
|
| |
| time_per_package: float = 5.0 |
| time_per_stop: float = 3.0 |
| base_route_time: float = 30.0 |
|
|
| |
| langchain_tracing_v2: bool = False |
| langchain_api_key: Optional[str] = None |
| langchain_project: str = "fair-dispatch-dev" |
|
|
| |
| google_api_key: Optional[str] = None |
| enable_gemini_explain: bool = False |
|
|
| @property |
| def is_production(self) -> bool: |
| return self.app_env == "production" |
|
|
| @property |
| def cors_origin_list(self) -> list[str]: |
| origins = [o.strip() for o in self.cors_origins.split(",") if o.strip()] |
| if not self.is_production: |
| origins.extend(["http://localhost:5173", "http://localhost:3000", "http://localhost:8000"]) |
| return origins |
|
|
|
|
| @lru_cache() |
| def get_settings() -> Settings: |
| """Get cached settings instance.""" |
| return Settings() |
|
|