fix: align whisper-server id allocation

parent 87a45ca3
......@@ -61,6 +61,8 @@ def _next_whisper_server_model_id(audio_models) -> str:
for model in audio_models or []:
if not isinstance(model, dict):
continue
if model.get("backend") != "whisper-server":
continue
match = re.fullmatch(r"whisper(\d+)", str(model.get("id") or "").strip())
if match:
used_suffixes.add(int(match.group(1)))
......@@ -1295,7 +1297,11 @@ async def api_model_configure(request: Request, username: str = Depends(require_
if gpu_device < 0:
raise HTTPException(status_code=400, detail="gpu_device must be >= 0")
for existing in config_manager.models_data.get("audio_models", []):
if isinstance(existing, dict) and existing.get("id") == model_id:
if (
isinstance(existing, dict)
and existing.get("backend") == "whisper-server"
and existing.get("id") == model_id
):
raise HTTPException(status_code=409, detail=f"whisper-server model '{model_id}' already exists")
entry = {
"id": model_id,
......
......@@ -211,7 +211,36 @@ def test_model_configure_defaults_missing_whisper_server_model_id_skips_non_whis
)
assert response.status_code == 200
assert cfg.models_data["audio_models"][-1]["id"] == "whisper1"
assert cfg.models_data["audio_models"][-1]["id"] == "whisper0"
app.dependency_overrides.clear()
def test_model_configure_allows_whisper_server_id_coexistence_with_other_audio_backends(monkeypatch, tmp_path):
from codai.admin import routes
cfg = _build_config(tmp_path)
cfg.models_data["audio_models"] = [
{"id": "whisper0", "backend": "faster-whisper"},
]
monkeypatch.setattr(routes, "config_manager", cfg, raising=False)
app, client = _build_admin_test_client(routes)
response = client.post(
"/admin/api/model-configure",
json={
"model_id": "whisper0",
"backend": "whisper-server",
"server_path": "/usr/local/bin/whisper-server",
"model_path": "/models/ggml-base.bin",
"port": 8744,
"gpu_device": 0,
"load_mode": "on-request",
},
)
assert response.status_code == 200
assert [m["backend"] for m in cfg.models_data["audio_models"]] == ["faster-whisper", "whisper-server"]
assert cfg.models_data["audio_models"][-1]["id"] == "whisper0"
app.dependency_overrides.clear()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment