| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- 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 / R2) & 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")
- # Cloudflare R2
- r2_account_id: str = Field("f97ce2711cc348200b0de273e48f2230", description="Cloudflare Account ID")
- r2_access_key_id: str = Field("", description="Cloudflare R2 Access Key ID")
- r2_secret_access_key: str = Field("", description="Cloudflare R2 Secret Access Key")
- r2_endpoint_url: str = Field(
- "https://f97ce2711cc348200b0de273e48f2230.r2.cloudflarestorage.com",
- description="Cloudflare R2 S3 Endpoint URL",
- )
- r2_bucket_name: str = Field("", description="Default Cloudflare R2 Bucket Name")
- r2_public_domain: str = Field("", description="R2 Public Domain for accessing files (e.g. https://pub-xxx.r2.dev or custom domain)")
- # -----------------------
- # LLM Configuration (OpenAI-compatible)
- # -----------------------
- llm_api_key: str = Field("", description="LLM 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()
|