Files
AIChatRoom/backend/config.py

51 lines
1.2 KiB
Python
Raw Normal View History

"""
应用配置模块
从环境变量加载配置项
"""
from pydantic_settings import BaseSettings
from typing import Optional
class Settings(BaseSettings):
"""应用配置类"""
# MongoDB配置
MONGODB_URL: str = "mongodb://localhost:27017"
MONGODB_DB: str = "ai_chatroom"
# 服务配置
HOST: str = "0.0.0.0"
PORT: int = 8000
DEBUG: bool = True
# 安全配置
SECRET_KEY: str = "your-secret-key-change-in-production"
ENCRYPTION_KEY: str = "your-encryption-key-32-bytes-long"
# CORS配置
CORS_ORIGINS: list = ["http://localhost:3000", "http://127.0.0.1:3000"]
# WebSocket配置
WS_HEARTBEAT_INTERVAL: int = 30
# 默认AI配置
DEFAULT_TIMEOUT: int = 60
DEFAULT_MAX_TOKENS: int = 2000
DEFAULT_TEMPERATURE: float = 0.7
# 代理配置(全局默认)
DEFAULT_HTTP_PROXY: Optional[str] = None
DEFAULT_HTTPS_PROXY: Optional[str] = None
# 速率限制
RATE_LIMIT_REQUESTS: int = 100
RATE_LIMIT_PERIOD: int = 60 # 秒
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
# 全局配置实例
settings = Settings()