fix(mlx-whisper): 修正 huggingface 仓库 ID 命名

mlx-community 上 Whisper 仓库的命名实际是 'whisper-{size}-mlx'(large-v3-turbo 例外,无 -mlx 后缀)。
之前 hardcode 拼成 'mlx-community/whisper-{size}' 在 HF 上不存在,下载会 404:

  Repository Not Found for url:
    https://huggingface.co/api/models/mlx-community/whisper-small/revision/main.

修复:
- 在 mlx_whisper_transcriber.py 加 MLX_MODEL_MAP(已用 huggingface API 核对过命名)+ resolve_mlx_repo_id() 帮助函数
- routers/config.py 的 _do_download_mlx_whisper 与 _check ... 路径生成都改用同一份映射表
- 给 transcriber_models_status 的每条 mlx 状态加 available 字段,避免后续若有不支持的 size 时静默失败

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
huangjianwu
2026-05-07 11:59:02 +08:00
parent 702b57c165
commit be5e1637fa
2 changed files with 45 additions and 9 deletions

View File

@@ -13,6 +13,31 @@ from events import transcription_finished
logger = get_logger(__name__)
# mlx-community 上的 Whisper 仓库命名不统一:常规版本是 'whisper-{size}-mlx'
# turbo 例外没有 -mlx 后缀。直接拼 'mlx-community/whisper-{size}' 会 404。
# 已用 https://huggingface.co/api/models?author=mlx-community&search=whisper 核对过。
MLX_MODEL_MAP = {
"tiny": "mlx-community/whisper-tiny-mlx",
"base": "mlx-community/whisper-base-mlx",
"small": "mlx-community/whisper-small-mlx",
"medium": "mlx-community/whisper-medium-mlx",
"large-v1": "mlx-community/whisper-large-v1-mlx",
"large-v2": "mlx-community/whisper-large-v2-mlx",
"large-v3": "mlx-community/whisper-large-v3-mlx",
"large-v3-turbo": "mlx-community/whisper-large-v3-turbo",
}
def resolve_mlx_repo_id(model_size: str) -> str:
if model_size not in MLX_MODEL_MAP:
raise ValueError(
f"不支持的 MLX Whisper 模型大小: {model_size}"
f"可选: {', '.join(MLX_MODEL_MAP.keys())}"
)
return MLX_MODEL_MAP[model_size]
class MLXWhisperTranscriber(Transcriber):
def __init__(
self,
@@ -21,13 +46,13 @@ class MLXWhisperTranscriber(Transcriber):
# 检查平台
if platform.system() != "Darwin":
raise RuntimeError("MLX Whisper 仅支持 Apple 平台")
# 检查环境变量
if os.environ.get("TRANSCRIBER_TYPE") != "mlx-whisper":
raise RuntimeError("必须设置环境变量 TRANSCRIBER_TYPE=mlx-whisper 才能使用 MLX Whisper")
self.model_size = model_size
self.model_name = f"mlx-community/whisper-{model_size}"
self.model_name = resolve_mlx_repo_id(model_size)
self.model_path = None
# 设置模型路径