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:
co-authored by
Claude Opus 5.5
parent
99b9cd71cd
commit
313892b6df
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user