Carry the vocabulary hint as prompt from the engines through the worker into every window

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas Winther
2026-10-29 21:44:06 +01:00
co-authored by Claude Opus 5.5
parent 99b9cd71cd
commit 313892b6df
5 changed files with 67 additions and 1 deletions
+18
View File
@@ -17,6 +17,13 @@ import {
type ProgressInfo,
} from "@huggingface/transformers";
import { resolveDefaultDtype } from "../lib/models";
import {
buildPromptPrefix,
installPromptSupport,
PROMPT_PREFIX_KWARG,
type PromptableModel,
type PromptTokenizer,
} from "./prompt";
import {
deviceAttempts,
dtypeRequiresF16,
@@ -410,6 +417,17 @@ async function transcribe(message: TranscribeMessage): Promise<void> {
if (message.task !== undefined) {
options.task = message.task;
}
// "Names and terms" hint (D-WS2a): one prefix per pass, applied by the
// generate() wrapper to every 30 s window (Transformers.js ignores
// `prompt_ids`, see src/worker/prompt.ts). The wrapper is idempotent.
const promptPrefix = buildPromptPrefix(
asr.tokenizer as unknown as PromptTokenizer,
message.prompt ?? "",
);
if (promptPrefix.length > 0) {
installPromptSupport(asr.model as unknown as PromptableModel);
options[PROMPT_PREFIX_KWARG] = promptPrefix;
}
const output = await asr(message.audio, options);