feat: add whisper-server builder defaults

parent 6b937272
...@@ -1312,7 +1312,7 @@ async def api_model_configure(request: Request, username: str = Depends(require_ ...@@ -1312,7 +1312,7 @@ async def api_model_configure(request: Request, username: str = Depends(require_
entry["used_vram_gb"] = data["used_vram_gb"] entry["used_vram_gb"] = data["used_vram_gb"]
config_manager.models_data.setdefault("audio_models", []).append(entry) config_manager.models_data.setdefault("audio_models", []).append(entry)
config_manager.save_models() config_manager.save_models()
return {"success": True} return {"success": True, "model_id": model_id, "model_path": model_path, "server_path": server_path}
path = data.get("path") or data.get("model_id", "") path = data.get("path") or data.get("model_id", "")
valid = {"text_models", "image_models", "audio_models", "tts_models", "vision_models", "video_models", valid = {"text_models", "image_models", "audio_models", "tts_models", "vision_models", "video_models",
"audio_gen_models", "embedding_models"} "audio_gen_models", "embedding_models"}
......
...@@ -1038,6 +1038,7 @@ function prefillWhisperServerFromGguf(path){ ...@@ -1038,6 +1038,7 @@ function prefillWhisperServerFromGguf(path){
const sourceSelect = document.getElementById('ws-model-source'); const sourceSelect = document.getElementById('ws-model-source');
const ggufSelect = document.getElementById('ws-gguf-select'); const ggufSelect = document.getElementById('ws-gguf-select');
const builder = document.getElementById('ws-model-builder'); const builder = document.getElementById('ws-model-builder');
resetWhisperServerBuilderDefaults();
if(sourceSelect){ if(sourceSelect){
sourceSelect.value = 'cached-gguf'; sourceSelect.value = 'cached-gguf';
} }
...@@ -1419,9 +1420,16 @@ async function addWhisperServerModel(){ ...@@ -1419,9 +1420,16 @@ async function addWhisperServerModel(){
}); });
const d = await r.json(); const d = await r.json();
if(!r.ok) throw new Error(d.detail || 'Failed to add whisper-server model'); if(!r.ok) throw new Error(d.detail || 'Failed to add whisper-server model');
document.getElementById('ws-model-id').value = ''; document.getElementById('ws-model-id').value = nextWhisperServerModelId();
document.getElementById('ws-server-path').value = ''; document.getElementById('ws-server-path').value = defaultWhisperServerPath();
resetWhisperServerBuilderDefaults(); document.getElementById('ws-model-source').value = 'cached-gguf';
document.getElementById('ws-gguf-select').value = d.model_path || '';
document.getElementById('ws-model-path').value = '';
document.getElementById('ws-port').value = '8744';
document.getElementById('ws-gpu-device').value = '0';
document.getElementById('ws-load-mode').value = 'on-request';
document.getElementById('ws-used-vram').value = '';
toggleWhisperModelSource();
refreshLocal(); refreshLocal();
}catch(e){ alert('Error: '+e.message); } }catch(e){ alert('Error: '+e.message); }
} }
......
...@@ -270,6 +270,34 @@ def test_model_configure_defaults_missing_whisper_server_path_uses_shutil_which_ ...@@ -270,6 +270,34 @@ def test_model_configure_defaults_missing_whisper_server_path_uses_shutil_which_
app.dependency_overrides.clear() app.dependency_overrides.clear()
def test_model_configure_preserves_explicit_whisper_server_model_id_and_server_path_overrides(monkeypatch, tmp_path):
from codai.admin import routes
cfg = _build_config(tmp_path)
monkeypatch.setattr(routes, "config_manager", cfg, raising=False)
monkeypatch.setattr(routes.shutil, "which", lambda _: "/opt/bin/whisper-server")
app, client = _build_admin_test_client(routes)
response = client.post(
"/admin/api/model-configure",
json={
"model_id": "custom-whisper-id",
"model_type": "audio_models",
"backend": "whisper-server",
"server_path": "/custom/bin/whisper-server",
"model_path": "/models/custom.gguf",
"port": 9123,
"gpu_device": 2,
"load_mode": "load",
},
)
assert response.status_code == 200
assert cfg.models_data["audio_models"][0]["id"] == "custom-whisper-id"
assert cfg.models_data["audio_models"][0]["server_path"] == "/custom/bin/whisper-server"
app.dependency_overrides.clear()
def test_model_configure_accepts_cached_gguf_whisper_server_model(monkeypatch, tmp_path): def test_model_configure_accepts_cached_gguf_whisper_server_model(monkeypatch, tmp_path):
from codai.admin import routes from codai.admin import routes
...@@ -630,12 +658,23 @@ def test_models_template_resets_whisper_server_builder_defaults_after_refresh_an ...@@ -630,12 +658,23 @@ def test_models_template_resets_whisper_server_builder_defaults_after_refresh_an
template = Path("codai/admin/templates/models.html").read_text() template = Path("codai/admin/templates/models.html").read_text()
assert "resetWhisperServerBuilderDefaults();" in template assert "resetWhisperServerBuilderDefaults();" in template
assert "document.getElementById('ws-model-id').value = '';" in template assert "document.getElementById('ws-model-id').value = nextWhisperServerModelId();" in template
assert "document.getElementById('ws-server-path').value = '';" in template assert "document.getElementById('ws-server-path').value = defaultWhisperServerPath();" in template
assert "resetWhisperServerBuilderDefaults();\n refreshLocal();" in template assert "document.getElementById('ws-model-path').value = '';" in template
assert "document.getElementById('ws-model-source').value = 'cached-gguf';" in template
assert "document.getElementById('ws-gguf-select').value = d.model_path || '';" in template
assert "toggleWhisperModelSource();\n refreshLocal();" in template
assert "refreshLocal();" in template assert "refreshLocal();" in template
def test_models_template_prefill_uses_reset_defaults_before_selecting_gguf():
template = Path("codai/admin/templates/models.html").read_text()
assert "resetWhisperServerBuilderDefaults();" in template
assert "sourceSelect.value = 'cached-gguf';" in template
assert "ggufSelect.value = path;" in template
def test_models_template_submits_whisper_server_source_and_resolved_gguf_path(): def test_models_template_submits_whisper_server_source_and_resolved_gguf_path():
template = Path("codai/admin/templates/models.html").read_text() template = Path("codai/admin/templates/models.html").read_text()
......
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