feat: prefill whisper-server builder defaults

parent d3d5896a
......@@ -1051,6 +1051,25 @@ function prefillWhisperServerFromGguf(path){
}
}
function nextWhisperServerModelId(){
const whisperModels = _localModels.filter(m => m.cacheType === 'whisper-server');
const existingIds = new Set(whisperModels.map(m => m.id || ''));
let suffix = 0;
while(existingIds.has(`whisper${suffix}`)) suffix += 1;
return `whisper${suffix}`;
}
function defaultWhisperServerPath(){
return '/usr/local/bin/whisper-server';
}
function resetWhisperServerBuilderDefaults(){
const modelIdInput = document.getElementById('ws-model-id');
const serverPathInput = document.getElementById('ws-server-path');
if(modelIdInput && !modelIdInput.value.trim()) modelIdInput.value = nextWhisperServerModelId();
if(serverPathInput && !serverPathInput.value.trim()) serverPathInput.value = defaultWhisperServerPath();
}
async function loadCachedModels(){
_localModels = [];
const hfEl = document.getElementById('hf-models-list');
......@@ -1142,6 +1161,7 @@ async function loadCachedModels(){
'<th></th></tr></thead><tbody>'+rows.join('')+'</tbody></table>';
}
ggufEl.insertAdjacentHTML('afterend', _renderWhisperServerRows(whisperModels));
resetWhisperServerBuilderDefaults();
}catch(e){
hfEl.innerHTML = ggufEl.innerHTML = `<span class="muted small">Error: ${esc(e.message)}</span>`;
}
......@@ -1399,6 +1419,8 @@ async function addWhisperServerModel(){
});
const d = await r.json();
if(!r.ok) throw new Error(d.detail || 'Failed to add whisper-server model');
document.getElementById('ws-model-id').value = '';
document.getElementById('ws-server-path').value = '';
refreshLocal();
}catch(e){ alert('Error: '+e.message); }
}
......
......@@ -603,6 +603,38 @@ def test_models_template_defines_whisper_server_gguf_prefill_helpers():
assert "prefillWhisperServerFromGguf(path)" in template
def test_models_template_defines_next_whisper_server_model_id_helper():
template = Path("codai/admin/templates/models.html").read_text()
assert "function nextWhisperServerModelId()" in template
assert "whisperModels.map(m => m.id || '')" in template
assert "while(existingIds.has(`whisper${suffix}`)) suffix += 1;" in template
assert "return `whisper${suffix}`;" in template
def test_models_template_defines_whisper_server_builder_default_helpers():
template = Path("codai/admin/templates/models.html").read_text()
assert "function defaultWhisperServerPath()" in template
assert "return '/usr/local/bin/whisper-server';" in template
assert "function resetWhisperServerBuilderDefaults()" in template
assert "const modelIdInput = document.getElementById('ws-model-id');" in template
assert "const serverPathInput = document.getElementById('ws-server-path');" in template
assert "if(modelIdInput && !modelIdInput.value.trim())" in template
assert "if(serverPathInput && !serverPathInput.value.trim())" in template
assert "modelIdInput.value = nextWhisperServerModelId();" in template
assert "serverPathInput.value = defaultWhisperServerPath();" in template
def test_models_template_resets_whisper_server_builder_defaults_after_refresh_and_add():
template = Path("codai/admin/templates/models.html").read_text()
assert "resetWhisperServerBuilderDefaults();" in template
assert "document.getElementById('ws-model-id').value = '';" in template
assert "document.getElementById('ws-server-path').value = '';" in template
assert "refreshLocal();" in template
def test_models_template_submits_whisper_server_source_and_resolved_gguf_path():
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