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:
1 parent
99b9cd71cd
commit
313892b6df
5 files changed
+67
-1
No files matched your search
@@ -77,6 +77,17 @@ describe("BrowserEngine", () => {
|
||||
expect("modelId" in message).toBe(false);
|
||||
});
|
||||
|
||||
test("forwards the vocabulary hint as `prompt`, and omits an empty one (D-WS2a)", () => {
|
||||
const worker = new FakeWorker();
|
||||
const engine = new BrowserEngine(worker);
|
||||
void engine.transcribe(new Float32Array(4), { prompt: "Maxwell\nVoid" });
|
||||
void engine.transcribe(new Float32Array(4), { prompt: "" });
|
||||
void engine.transcribe(new Float32Array(4));
|
||||
expect(worker.posted[0]!.message.prompt).toBe("Maxwell\nVoid");
|
||||
expect("prompt" in worker.posted[1]!.message).toBe(false);
|
||||
expect("prompt" in worker.posted[2]!.message).toBe(false);
|
||||
});
|
||||
|
||||
test("asks the worker to stream only when a consumer listens", () => {
|
||||
const worker = new FakeWorker();
|
||||
const engine = new BrowserEngine(worker);
|
||||
@@ -241,6 +252,23 @@ describe("ServerEngine", () => {
|
||||
expect(url).not.toContain("language");
|
||||
});
|
||||
|
||||
test("sends the vocabulary hint as the `prompt` query param, only when non-empty", async () => {
|
||||
const urls: string[] = [];
|
||||
const engine = new ServerEngine(async (input) => {
|
||||
urls.push(input);
|
||||
return ndjsonResponse([{ type: "result", text: "", chunks: [] }]);
|
||||
});
|
||||
await engine.transcribe(new Float32Array(4), {
|
||||
modelId: "onnx-community/whisper-tiny",
|
||||
prompt: "Århus, Voices of the Void",
|
||||
});
|
||||
await engine.transcribe(new Float32Array(4), { modelId: "onnx-community/whisper-tiny", prompt: "" });
|
||||
expect(new URL(urls[0]!, "http://localhost").searchParams.get("prompt")).toBe(
|
||||
"Århus, Voices of the Void",
|
||||
);
|
||||
expect(urls[1]).not.toContain("prompt");
|
||||
});
|
||||
|
||||
test("requires a modelId", () => {
|
||||
const engine = new ServerEngine(async () => ndjsonResponse([]));
|
||||
expect(engine.transcribe(new Float32Array(4))).rejects.toThrow(/model id/);
|
||||
|
||||
Reference in new issue
Block a user