51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
from functools import lru_cache
|
|
from typing import Any
|
|
|
|
from pydantic import field_validator
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env",
|
|
env_file_encoding="utf-8",
|
|
case_sensitive=False,
|
|
extra="ignore",
|
|
)
|
|
|
|
app_name: str = "财务 AI 助手 API"
|
|
app_version: str = "1.0.0"
|
|
debug: bool = True
|
|
secret_key: str = "change-me-in-production"
|
|
allowed_origins: list[str] = ["http://localhost:3000"]
|
|
|
|
database_url: str = "postgresql+asyncpg://s2f_user:s2f_password@localhost:5432/s2f_db"
|
|
|
|
jwt_secret_key: str = "change-me-in-production"
|
|
jwt_algorithm: str = "HS256"
|
|
jwt_access_token_expire_minutes: int = 60
|
|
|
|
openai_api_key: str = ""
|
|
openai_model: str = "gpt-4-turbo-preview"
|
|
zhipu_api_key: str = ""
|
|
ai_provider: str = "zhipu"
|
|
ai_api_key: str = ""
|
|
|
|
upload_dir: str = "./uploads"
|
|
max_upload_size: int = 10_485_760
|
|
|
|
log_level: str = "INFO"
|
|
|
|
@field_validator("allowed_origins", mode="before")
|
|
@classmethod
|
|
def parse_allowed_origins(cls, value: Any) -> list[str]:
|
|
if isinstance(value, str):
|
|
return [origin.strip() for origin in value.split(",") if origin.strip()]
|
|
if isinstance(value, list):
|
|
return value
|
|
return ["http://localhost:3000"]
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
return Settings() |