| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- from functools import lru_cache
- from pydantic_settings import BaseSettings, SettingsConfigDict
- from pydantic import Field
- class Settings(BaseSettings):
- # -----------------------
- # App
- # -----------------------
- app_name: str = "MyApp"
- env: str = "PROD"
- debug: bool = False
- # -----------------------
- # Database / Cache
- # -----------------------
- database_url: str = Field(..., description="Async database DSN")
- redis_url: str
- # -----------------------
- # Security / API Keys
- # -----------------------
- stripe_api_key: str
- stripe_webhook_secret: str
- creem_api_key: str = Field("", description="Creem API Key")
- creem_webhook_secret: str = Field("", description="Creem Webhook Secret")
- creem_base_url: str = Field("https://test-api.creem.io", description="Creem Base URL (or https://api.creem.io)")
- creem_product_id: str = Field("", description="Default Creem Product ID (optional)")
- telegram_api_token: str = Field("", description="Telegram bot API token")
- wechat_api_token: str = Field("", description="Wechat webhook API token")
- whatsapp_api_base_url: str = Field("https://waha.text.skin", description="Whatsapp API base url")
- whatsapp_api_key: str = Field("", description="Whatsapp API key")
- whatsapp_session: str = Field("default", description="Whatsapp session")
- # -----------------------
- # Storage (SeaweedFS) & Network
- # -----------------------
- api_base_url: str = Field("https://api.text.skin", description="Public API base URL for resource links")
- seaweedfs_master_url: str = Field("http://seaweedfs-master:9333", description="SeaweedFS Master URL")
- seaweedfs_volume_override_host: str = Field("", description="Optional host/IP to override SeaweedFS Volume address for cross-network access")
- # -----------------------
- # LLM Configuration (OpenAI-compatible)
- # -----------------------
- llm_api_key: str = Field("", description="LLM API Key (defaults to openai_api_key)")
- llm_base_url: str = Field("https://api.deepseek.com", description="OpenAI-compatible Base URL")
- llm_model: str = Field("deepseek-v4-flash", description="Default model name, e.g., deepseek-v4-flash, deepseek-v4-pro")
- llm_temperature: float = Field(0.0, description="LLM sampling temperature")
- llm_timeout_seconds: int = Field(60, description="LLM request timeout in seconds")
- model_config = SettingsConfigDict(
- env_file=".env",
- env_file_encoding="utf-8",
- case_sensitive=False,
- extra="ignore",
- )
- @lru_cache
- def get_settings() -> Settings:
- """
- 避免多次实例化 Settings(FastAPI 官方推荐)
- """
- return Settings()
- settings = get_settings()
|