60 lines
1.7 KiB
Python
60 lines
1.7 KiB
Python
from pydantic_settings import BaseSettings
|
||
from pathlib import Path
|
||
import os
|
||
|
||
|
||
class Settings(BaseSettings):
|
||
# 应用
|
||
APP_NAME: str = "AI 文档模板生成系统"
|
||
APP_VERSION: str = "1.0.0"
|
||
DEBUG: bool = True
|
||
|
||
# === 数据库 MySQL ===
|
||
DB_HOST: str = "localhost"
|
||
DB_PORT: int = 3306
|
||
DB_USER: str = "docforge"
|
||
DB_PASSWORD: str = "docforge123"
|
||
DB_NAME: str = "doc_forge"
|
||
@property
|
||
def DATABASE_URL(self) -> str:
|
||
return f"mysql+asyncmy://{self.DB_USER}:{self.DB_PASSWORD}@{self.DB_HOST}:{self.DB_PORT}/{self.DB_NAME}?charset=utf8mb4"
|
||
|
||
# === MinIO 文件存储 ===
|
||
MINIO_ENDPOINT: str = "localhost:9000"
|
||
MINIO_ACCESS_KEY: str = "docforge"
|
||
MINIO_SECRET_KEY: str = "docforge123"
|
||
MINIO_BUCKET_TEMPLATES: str = "doc-forge-templates"
|
||
MINIO_BUCKET_UPLOADS: str = "doc-forge-uploads"
|
||
MINIO_BUCKET_OUTPUTS: str = "doc-forge-outputs"
|
||
MINIO_USE_SSL: bool = False
|
||
|
||
# 本地缓存目录(MinIO 文件的本地临时缓存)
|
||
LOCAL_CACHE_DIR: str = "local_cache"
|
||
|
||
# 文件上传限制
|
||
MAX_UPLOAD_SIZE: int = 50 * 1024 * 1024 # 50MB
|
||
ALLOWED_EXTENSIONS: list = [".docx", ".doc", ".xlsx", ".xls", ".xlsm", ".csv", ".pdf", ".txt", ".md", ".json"]
|
||
|
||
# 加密(用于 API Key 加密)
|
||
ENCRYPTION_KEY: str = "change-this-to-a-32-byte-key-in-production!!"
|
||
|
||
# AI 模型默认配置
|
||
AI_REQUEST_TIMEOUT: int = 60
|
||
AI_MAX_RETRIES: int = 3
|
||
AI_MAX_CONCURRENT: int = 5
|
||
AI_GLOBAL_CONCURRENT: int = 10
|
||
|
||
# 服务端口
|
||
HOST: str = "0.0.0.0"
|
||
PORT: int = 8000
|
||
|
||
class Config:
|
||
env_file = ".env"
|
||
env_file_encoding = "utf-8"
|
||
|
||
|
||
settings = Settings()
|
||
|
||
# 创建本地缓存目录
|
||
os.makedirs(settings.LOCAL_CACHE_DIR, exist_ok=True)
|