From a4c4ee1f5bb3014c04ae50dd8c00272e1a0518bc Mon Sep 17 00:00:00 2001 From: gexianmeng Date: Fri, 23 May 2025 17:34:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85minmax=E8=AF=AD=E9=9F=B3?= =?UTF-8?q?=E5=85=8B=E9=9A=86=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/BowongModalFunctions/api.py | 4 +++- src/BowongModalFunctions/config.py | 37 +++++++++++++++++++++++++++++- src/cluster/app.py | 4 ++-- src/cluster/web.py | 4 ++-- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/BowongModalFunctions/api.py b/src/BowongModalFunctions/api.py index 8e07730..e66c477 100644 --- a/src/BowongModalFunctions/api.py +++ b/src/BowongModalFunctions/api.py @@ -4,8 +4,9 @@ import sentry_sdk from sentry_sdk.integrations.loguru import LoguruIntegration, LoggingLevels from sentry_sdk.integrations.fastapi import FastApiIntegration from fastapi.middleware.cors import CORSMiddleware + from .utils.KVCache import KVCache -from .router import ffmpeg, cache, comfyui +from .router import ffmpeg, cache, comfyui, text2speech from .config import WorkerConfig config = WorkerConfig() @@ -82,3 +83,4 @@ async def scalar(): web_app.include_router(ffmpeg.router) web_app.include_router(cache.router) web_app.include_router(comfyui.router) +web_app.include_router(text2speech.router) # 添加文本转语音路由 diff --git a/src/BowongModalFunctions/config.py b/src/BowongModalFunctions/config.py index f02e205..0af1b12 100644 --- a/src/BowongModalFunctions/config.py +++ b/src/BowongModalFunctions/config.py @@ -19,4 +19,39 @@ class WorkerConfig(BaseSettings): comfyui_s3_input: Optional[str] = Field(default="comfyui-input", description="ComfyUI input S3文件夹名") comfyui_s3_output: Optional[str] = Field(default="comfyui-output", description="ComfyUI output S3文件夹名") - modal_config: Any = SettingsConfigDict() + # MiniMax API 配置 + # BaseSettings 会自动从环境变量 MINIMAX_GROUP_ID 读取值 + minimax_group_id: str = Field( + default="", + description="MiniMax API 组ID" + ) + + # BaseSettings 会自动从环境变量 MINIMAX_API_KEY 读取值 + minimax_api_key: str = Field( + default="", + description="MiniMax API 密钥" + ) + + # 语音克隆相关配置 + voice_clone_max_file_size: int = Field( + default=20 * 1024 * 1024, # 20MB + description="语音克隆最大文件大小限制" + ) + + voice_clone_allowed_formats: list = Field( + default=[".mp3", ".wav", ".m4a", ".aac", ".ogg"], + description="语音克隆支持的音频格式" + ) + + voice_clone_output_dir: str = Field( + default="voice_clone/minmax", + description="语音克隆输出目录(相对于S3挂载目录)" + ) + + model_config = SettingsConfigDict( + # 自动从环境变量加载,大小写不敏感 + case_sensitive=False, + # 支持从 .env 文件加载(如果存在) + env_file=".env", + env_file_encoding="utf-8" + ) diff --git a/src/cluster/app.py b/src/cluster/app.py index 344e116..5cc01c3 100644 --- a/src/cluster/app.py +++ b/src/cluster/app.py @@ -10,8 +10,8 @@ config = WorkerConfig() app = modal.App(config.modal_app_name, include_source=False, - secrets=[modal.Secret.from_name("cf-kv-secret", - environment_name=config.modal_environment)]) + secrets=[modal.Secret.from_name("cf-kv-secret", environment_name=config.modal_environment), + modal.Secret.from_name("minimax-api", environment_name=config.modal_environment)]) app.include(media_app) app.include(ffmpeg_app) diff --git a/src/cluster/web.py b/src/cluster/web.py index 75d7842..c32c925 100644 --- a/src/cluster/web.py +++ b/src/cluster/web.py @@ -24,12 +24,12 @@ with fastapi_image.imports(): @app.function(scaledown_window=60, secrets=[ modal.Secret.from_name("cf-kv-secret", environment_name='dev'), + modal.Secret.from_name("minimax-api", environment_name=config.modal_environment) ], volumes={ config.S3_mount_dir: modal.CloudBucketMount( bucket_name=config.S3_bucket_name, - secret=modal.Secret.from_name("aws-s3-secret", - environment_name=config.modal_environment), + secret=modal.Secret.from_name("aws-s3-secret", environment_name=config.modal_environment), ), }, )