Spaces:
Runtime error
Runtime error
File size: 1,777 Bytes
4c4c8a0 ef865f2 4c4c8a0 ef865f2 4c4c8a0 ef865f2 c6f3411 ef865f2 4c4c8a0 3f78860 4c4c8a0 098f3ea 4c4c8a0 098f3ea 4c4c8a0 ef865f2 96615d4 ef865f2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | import os
from backend import config_local as _local
def _cfg(key: str, default):
# Priority: environment variable > config_local.py > hardcoded default
if key in os.environ:
raw = os.environ[key]
# Coerce to the same type as the default (e.g. int for JWT_EXPIRE_HOURS)
if isinstance(default, int):
return int(raw)
return raw
return getattr(_local, key, default)
class Settings:
MISTRAL_API_KEY: str = _cfg("MISTRAL_API_KEY", "")
DATABASE_URL: str = _cfg("DATABASE_URL", "")
ALLOWED_ORIGINS: str = _cfg("ALLOWED_ORIGINS", "http://localhost:5173,http://localhost:3000")
UPLOAD_DIR: str = "backend/uploads"
LLM_TIMEOUT: int = 60
HTTP_TIMEOUT: int = 120
RESPONSE_TRUNCATION_LIMIT: int = 4000
LLM_MODEL: str = _cfg("LLM_MODEL", "mistral-large-latest")
LLM_FALLBACK_MODEL: str = _cfg("LLM_FALLBACK_MODEL", "open-mistral-7b")
MAX_TOKENS_PER_SESSION: int = _cfg("MAX_TOKENS_PER_SESSION", 0)
AUTH_USERNAME: str = _cfg("AUTH_USERNAME", "admin")
AUTH_PASSWORD: str = _cfg("AUTH_PASSWORD", "changeme")
JWT_SECRET: str = _cfg("JWT_SECRET", "change-this-secret-in-production")
JWT_EXPIRE_HOURS: int = _cfg("JWT_EXPIRE_HOURS", 24)
ENCRYPTION_KEY: str = _cfg("ENCRYPTION_KEY", "")
# Supabase — read from config_local.py first, then env vars
SUPABASE_URL: str = _cfg("SUPABASE_URL", "")
SUPABASE_KEY: str = _cfg("SUPABASE_KEY", "")
SUPABASE_SERVICE_ROLE_KEY: str = _cfg("SUPABASE_SERVICE_ROLE_KEY", "")
SUPABASE_STORAGE_BUCKET: str = _cfg("SUPABASE_STORAGE_BUCKET", "assets")
@property
def allowed_origins_list(self) -> list[str]:
return [o.strip() for o in self.ALLOWED_ORIGINS.split(",") if o.strip()]
settings = Settings()
|