nikeshn commited on
Commit
c8e1f58
·
verified ·
1 Parent(s): 600046a

Update src/config.py

Browse files
Files changed (1) hide show
  1. 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 os
 
4
 
5
  class Settings(BaseSettings):
6
- # API Keys from HF Secrets
7
- openai_api_key: str = os.getenv("OPENAI_API_KEY", "")
8
- anthropic_api_key: str = os.getenv("ANTHROPIC_API_KEY", "")
9
- primo_api_key: str = os.getenv("PRIMO_API_KEY", "")
10
-
 
 
 
 
 
 
11
  # Security
12
- admin_password: str = os.getenv("ADMIN_PASSWORD", "")
13
- session_secret: str = os.getenv("SESSION_SECRET", "default-secret-change-me")
14
-
15
  # App settings
16
- environment: str = "production"
17
  maintenance_mode: bool = False
18
  max_results: int = 5
19
-
20
- class Config:
21
- case_sensitive = False
22
 
23
- @lru_cache()
24
- def get_settings():
 
 
 
 
 
 
 
 
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()