Compare commits

..

2 Commits
0.6.7 ... 0.6.8

Author SHA1 Message Date
8f89f5e3cf embedding worker fix
All checks were successful
Publish Library / Build NPM Project (push) Successful in 28s
Publish Library / Tag Version (push) Successful in 5s
2026-02-12 20:18:56 -05:00
5bd41f8c6a worker fix?
All checks were successful
Publish Library / Build NPM Project (push) Successful in 29s
Publish Library / Tag Version (push) Successful in 5s
2026-02-12 20:17:31 -05:00
5 changed files with 6 additions and 4 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@ztimson/ai-utils", "name": "@ztimson/ai-utils",
"version": "0.6.7", "version": "0.6.8",
"description": "AI Utility library", "description": "AI Utility library",
"author": "Zak Timson", "author": "Zak Timson",
"license": "MIT", "license": "MIT",

View File

@@ -84,6 +84,7 @@ function combineSpeakerTranscript(chunks: any[], speakers: any[]): string {
parentPort?.on('message', async ({ file, speaker, model, modelDir }) => { parentPort?.on('message', async ({ file, speaker, model, modelDir }) => {
try { try {
console.log('worker', file);
if(!whisperPipeline) whisperPipeline = await pipeline('automatic-speech-recognition', `Xenova/${model}`, {cache_dir: modelDir, quantized: true}); if(!whisperPipeline) whisperPipeline = await pipeline('automatic-speech-recognition', `Xenova/${model}`, {cache_dir: modelDir, quantized: true});
// Prepare audio file (convert to mono channel wave) // Prepare audio file (convert to mono channel wave)

View File

@@ -7,6 +7,7 @@ export class Audio {
constructor(private ai: Ai) {} constructor(private ai: Ai) {}
asr(file: string, options: { model?: string; speaker?: boolean } = {}): AbortablePromise<string | null> { asr(file: string, options: { model?: string; speaker?: boolean } = {}): AbortablePromise<string | null> {
console.log('audio', file);
const { model = this.ai.options.asr || 'whisper-base', speaker = false } = options; const { model = this.ai.options.asr || 'whisper-base', speaker = false } = options;
let aborted = false; let aborted = false;
const abort = () => { aborted = true; }; const abort = () => { aborted = true; };

View File

@@ -3,9 +3,9 @@ import { parentPort } from 'worker_threads';
let embedder: any; let embedder: any;
parentPort?.on('message', async ({ id, text, model, modelDir }) => { parentPort?.on('message', async ({text, model, modelDir }) => {
if(!embedder) embedder = await pipeline('feature-extraction', 'Xenova/' + model, {quantized: true, cache_dir: modelDir}); if(!embedder) embedder = await pipeline('feature-extraction', 'Xenova/' + model, {quantized: true, cache_dir: modelDir});
const output = await embedder(text, { pooling: 'mean', normalize: true }); const output = await embedder(text, { pooling: 'mean', normalize: true });
const embedding = Array.from(output.data); const embedding = Array.from(output.data);
parentPort?.postMessage({ id, embedding }); parentPort?.postMessage({embedding});
}); });

View File

@@ -271,7 +271,7 @@ class LLM {
worker.on('exit', (code) => { worker.on('exit', (code) => {
if(code !== 0) reject(new Error(`Worker exited with code ${code}`)); if(code !== 0) reject(new Error(`Worker exited with code ${code}`));
}); });
worker.postMessage({text, model: this.ai.options?.embedder || 'bge-small-en-v1.5', path: this.ai.options.path}); worker.postMessage({text, model: this.ai.options?.embedder || 'bge-small-en-v1.5', modelDir: this.ai.options.path});
}); });
}; };
const chunks = this.chunk(target, maxTokens, overlapTokens); const chunks = this.chunk(target, maxTokens, overlapTokens);