41 lines
1.2 KiB
Python
41 lines
1.2 KiB
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 = ""
|
|
dashscope_api_key: str = ""
|
|
# 华北2(北京)业务空间时需填:https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v1
|
|
# 普通 API Key 调用留空即可。
|
|
dashscope_base_http_api_url: str = ""
|
|
host: str = "127.0.0.1"
|
|
port: int = 8800
|
|
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()
|