Files
ai_game/server/app/config.py
2026-03-04 18:31:48 +08:00

38 lines
867 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
配置管理
"""
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服务配置预留
openai_api_key: str = ""
openai_base_url: str = "https://api.openai.com/v1"
@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()