Run Edgewise in a Web Worker so model loading and inference never block the page.
In a worker file:
import { serveWorker } from 'edgewise/worker';serveWorker(); Copy
import { serveWorker } from 'edgewise/worker';serveWorker();
On the page:
import { connectWorker } from 'edgewise/worker';const ew = connectWorker(new Worker(new URL('./edgewise.worker.ts', import.meta.url), { type: 'module' }));for await (const delta of ew.generate({ model: 'text:default', input: 'Hi' })) out.append(delta); Copy
import { connectWorker } from 'edgewise/worker';const ew = connectWorker(new Worker(new URL('./edgewise.worker.ts', import.meta.url), { type: 'module' }));for await (const delta of ew.generate({ model: 'text:default', input: 'Hi' })) out.append(delta);
The page-side object has the same verbs and options as the main package. Streams, events, cancel, progress, tools (executed on the page), schemas (checked on the page), microphone sources and streamed text for speak() all cross the worker boundary.
Run Edgewise in a Web Worker so model loading and inference never block the page.
In a worker file:
On the page:
The page-side object has the same verbs and options as the main package. Streams, events, cancel, progress, tools (executed on the page), schemas (checked on the page), microphone sources and streamed text for speak() all cross the worker boundary.