37 lines
954 B
Python
37 lines
954 B
Python
from functools import lru_cache
|
|
from pathlib import Path
|
|
|
|
from dotenv import load_dotenv
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
# .env 在仓库根(server/ 的上一级),供各部分共用
|
|
_ROOT_DIR = Path(__file__).resolve().parents[2]
|
|
load_dotenv(_ROOT_DIR / ".env")
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""运行时与密钥。模型清单见 config/models.yaml。"""
|
|
|
|
model_config = SettingsConfigDict(
|
|
env_file=str(_ROOT_DIR / ".env"),
|
|
env_file_encoding="utf-8",
|
|
extra="ignore",
|
|
)
|
|
|
|
deepseek_api_key: str = ""
|
|
openai_api_key: str = ""
|
|
host: str = "127.0.0.1"
|
|
port: int = 8000
|
|
cors_origins: str = ""
|
|
|
|
@property
|
|
def cors_origin_list(self) -> list[str]:
|
|
if not self.cors_origins.strip():
|
|
return []
|
|
return [o.strip() for o in self.cors_origins.split(",") if o.strip()]
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
return Settings()
|