feat: proxy POST /model/unload endpoint
All checks were successful
Build & Push Docker Image / build-and-push (push) Successful in 43s

- Add unloadModel() to whisper.ts: POSTs to /model/unload with 10s
  timeout, returns parsed JSON body, throws on non-ok response
- Create src/routes/api/model/unload/+server.ts: thin POST proxy,
  passes whisper's response through, returns 502 if whisper unreachable
- Add 3 unloadModel tests (success, WHISPER_URL config, error propagation)
  — 147/147 passing

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Giancarmine Salucci
2026-05-09 15:48:47 +02:00
parent 04142b17a8
commit 53f874aec7
3 changed files with 61 additions and 1 deletions

View File

@@ -127,6 +127,17 @@ export async function submitJob(
throw new Error(`Whisper model did not become ready after ${maxAttempts} attempts`);
}
/** Unload the model from VRAM. Throws if the whisper server returns non-ok. */
export async function unloadModel(): Promise<{ ok: boolean }> {
const { default: fetch } = await import('node-fetch');
const res = await fetch(`${whisperUrl()}/model/unload`, {
method: 'POST',
signal: AbortSignal.timeout(10000)
});
if (!res.ok) throw new Error(`/model/unload returned ${res.status}`);
return res.json() as Promise<{ ok: boolean }>;
}
/**
* Cancel a queued or running job on the whisper server (best-effort).
* Errors are silently ignored — local job status is already set to cancelled.