Update src/config.py
Browse files- src/config.py +29 -16
src/config.py
CHANGED
|
@@ -1,25 +1,38 @@
|
|
| 1 |
-
from pydantic_settings import BaseSettings
|
|
|
|
| 2 |
from functools import lru_cache
|
| 3 |
-
import
|
|
|
|
| 4 |
|
| 5 |
class Settings(BaseSettings):
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# Security
|
| 12 |
-
admin_password: str =
|
| 13 |
-
session_secret: str =
|
| 14 |
-
|
| 15 |
# App settings
|
| 16 |
-
environment:
|
| 17 |
maintenance_mode: bool = False
|
| 18 |
max_results: int = 5
|
| 19 |
-
|
| 20 |
-
class Config:
|
| 21 |
-
case_sensitive = False
|
| 22 |
|
| 23 |
-
@
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
return Settings()
|
|
|
|
| 1 |
+
from pydantic_settings import BaseSettings, SettingsConfigDict
|
| 2 |
+
from pydantic import field_validator
|
| 3 |
from functools import lru_cache
|
| 4 |
+
from typing import Literal
|
| 5 |
+
|
| 6 |
|
| 7 |
class Settings(BaseSettings):
|
| 8 |
+
model_config = SettingsConfigDict(
|
| 9 |
+
case_sensitive=False,
|
| 10 |
+
env_file=".env",
|
| 11 |
+
env_file_encoding="utf-8",
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
# API Keys — injected from HF Space secrets as env vars
|
| 15 |
+
openai_api_key: str = ""
|
| 16 |
+
anthropic_api_key: str = "" # optional — only needed for Claude model
|
| 17 |
+
primo_api_key: str = "" # optional — search falls back gracefully
|
| 18 |
+
|
| 19 |
# Security
|
| 20 |
+
admin_password: str = ""
|
| 21 |
+
session_secret: str = ""
|
| 22 |
+
|
| 23 |
# App settings
|
| 24 |
+
environment: Literal["development", "production"] = "production"
|
| 25 |
maintenance_mode: bool = False
|
| 26 |
max_results: int = 5
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
+
@field_validator("max_results")
|
| 29 |
+
@classmethod
|
| 30 |
+
def reasonable_max_results(cls, v: int) -> int:
|
| 31 |
+
if not 1 <= v <= 20:
|
| 32 |
+
raise ValueError("max_results must be between 1 and 20")
|
| 33 |
+
return v
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
@lru_cache
|
| 37 |
+
def get_settings() -> Settings:
|
| 38 |
return Settings()
|