Transcripts: ask the whisper service to download its model first
build-container / build (push) Failing after 6m42s

This commit is contained in:
nmemmert committed 2026-10-23 11:20:31 -04:00
1 parent 40a74e6cbe
commit 05e6b19bfa
1 file changed
+4
+4
View File
@@ -69,7 +69,11 @@ const jobs = new Map(); // key -> { state: 'running' | 'error', since, error }
let chain = Promise.resolve(); // one at a time: it is heavy
const fileOf = key => path.join(cfg.dir, key + '.json');
const keyFor = (kind, id, src) => crypto.createHash('sha1').update(kind + '|' + id + '|' + src).digest('hex');
let modelReady = null; // the service must have the model on disk before it can use it: ask for it once (a no-op when it is already there)
const ensureModel = () => modelReady || (modelReady = fetch(cfg.api + '/v1/models/' + cfg.model, { method: 'POST', signal: AbortSignal.timeout(30 * 60e3) })
.then(r => { if (!r.ok && r.status !== 409) throw new Error('status ' + r.status); }).catch(e => { modelReady = null; if (/^status 4\d\d/.test(e.message)) return; throw e; }));
async function whisper(file, name) {
try { await ensureModel(); } catch (e) { throw new Error(`Could not reach the transcription service at ${cfg.api} (${why(e)}). Is the whisper container running? Check its log.`); }
const form = new FormData();
form.append('file', await fs.openAsBlob(file), name || 'audio');
form.append('model', cfg.model); form.append('response_format', 'verbose_json'); form.append('timestamp_granularities[]', 'segment');