51 lines
1.2 KiB
Python
51 lines
1.2 KiB
Python
"""
|
|
配置管理
|
|
"""
|
|
from pydantic_settings import BaseSettings
|
|
from functools import lru_cache
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""应用配置"""
|
|
# 数据库配置
|
|
db_host: str = "localhost"
|
|
db_port: int = 3306
|
|
db_user: str = "root"
|
|
db_password: str = ""
|
|
db_name: str = "stardom_story"
|
|
|
|
# 服务配置
|
|
server_host: str = "0.0.0.0"
|
|
server_port: int = 3000
|
|
debug: bool = True
|
|
|
|
# AI 服务配置
|
|
ai_service_enabled: bool = True
|
|
ai_provider: str = "deepseek"
|
|
|
|
# DeepSeek 配置
|
|
deepseek_api_key: str = ""
|
|
deepseek_base_url: str = "https://api.deepseek.com/v1"
|
|
deepseek_model: str = "deepseek-chat"
|
|
|
|
# OpenAI 配置(备用)
|
|
openai_api_key: str = ""
|
|
openai_base_url: str = "https://api.openai.com/v1"
|
|
|
|
# 微信小游戏配置(预留)
|
|
wx_appid: str = ""
|
|
wx_secret: str = ""
|
|
|
|
@property
|
|
def database_url(self) -> str:
|
|
return f"mysql+aiomysql://{self.db_user}:{self.db_password}@{self.db_host}:{self.db_port}/{self.db_name}"
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
env_file_encoding = "utf-8"
|
|
|
|
|
|
@lru_cache()
|
|
def get_settings() -> Settings:
|
|
return Settings()
|