Compare commits

...

4 Commits
0.5.1 ... 0.5.5

Author SHA1 Message Date
8c64129200 Removed log statement
All checks were successful
Publish Library / Build NPM Project (push) Successful in 27s
Publish Library / Tag Version (push) Successful in 5s
2026-02-11 21:58:39 -05:00
013aa942c0 Added save directory for embedder
All checks were successful
Publish Library / Build NPM Project (push) Successful in 33s
Publish Library / Tag Version (push) Successful in 4s
2026-02-11 21:45:54 -05:00
c8d5660b1a Enable quantized embedder for speed boost
All checks were successful
Publish Library / Build NPM Project (push) Successful in 23s
Publish Library / Tag Version (push) Successful in 5s
2026-02-11 20:28:14 -05:00
f2c66b0cb8 Updated default embedder
All checks were successful
Publish Library / Build NPM Project (push) Successful in 39s
Publish Library / Tag Version (push) Successful in 8s
2026-02-11 20:23:50 -05:00
5 changed files with 17 additions and 8 deletions

View File

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

View File

@@ -10,6 +10,8 @@ export type AbortablePromise<T> = Promise<T> & {
export type AiOptions = {
/** Path to models */
path?: string;
/** Embedding model */
embedder?: string; // all-MiniLM-L6-v2, bge-small-en-v1.5, bge-large-en-v1.5
/** Large language models, first is default */
llm?: Omit<LLMRequest, 'model'> & {
models: {[model: string]: AnthropicConfig | OllamaConfig | OpenAiConfig};

View File

@@ -26,7 +26,7 @@ export class Anthropic extends LLMProvider {
h[c.is_error ? 'error' : 'content'] = c.content;
});
}
history[orgI].content = history[orgI].content.filter((c: any) => c.type == 'text').map((c: any) => c.text).join('\n\n');
history[orgI].content = history[orgI].content?.filter((c: any) => c.type == 'text').map((c: any) => c.text).join('\n\n');
if(!history[orgI].content) history.splice(orgI, 1);
}
if(!history[orgI].timestamp) history[orgI].timestamp = Date.now();
@@ -119,7 +119,6 @@ export class Anthropic extends LLMProvider {
if(options.stream) options.stream({tool: toolCall.name});
if(!tool) return {tool_use_id: toolCall.id, is_error: true, content: 'Tool not found'};
try {
console.log(typeof tool.fn);
const result = await tool.fn(toolCall.input, options?.stream, this.ai);
return {type: 'tool_result', tool_use_id: toolCall.id, content: JSONSanitize(result)};
} catch (err: any) {

View File

@@ -1,11 +1,14 @@
import { pipeline } from '@xenova/transformers';
import { parentPort } from 'worker_threads';
let model: any;
let embedder: any;
parentPort?.on('message', async ({ id, text }) => {
if(!model) model = await pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2');
const output = await model(text, { pooling: 'mean', normalize: true });
parentPort?.on('message', async ({ id, text, model, path }) => {
if(!embedder) embedder = await pipeline('feature-extraction', 'Xenova/' + model, {
quantized: true,
cache_dir: path,
});
const output = await embedder(text, { pooling: 'mean', normalize: true });
const embedding = Array.from(output.data);
parentPort?.postMessage({ id, embedding });
});

View File

@@ -271,7 +271,12 @@ class LLM {
return new Promise((resolve, reject) => {
const id = this.embedId++;
this.embedQueue.set(id, { resolve, reject });
this.embedWorker?.postMessage({ id, text });
this.embedWorker?.postMessage({
id,
text,
model: this.ai.options?.embedder || 'bge-small-en-v1.5',
path: this.ai.options.path
});
});
};
const chunks = this.chunk(target, maxTokens, overlapTokens);