Removed redundant llama protocol (Use openai)
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/ai-utils",
|
"name": "@ztimson/ai-utils",
|
||||||
"version": "1.1.0",
|
"version": "1.2.0",
|
||||||
"description": "AI Utility library",
|
"description": "AI Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import * as os from 'node:os';
|
import * as os from 'node:os';
|
||||||
import LLM, {AnthropicConfig, OllamaConfig, OpenAiConfig, LLMRequest} from './llm';
|
import LLM, {AnthropicConfig, OpenAiConfig, LLMRequest} from './llm';
|
||||||
import { Audio } from './audio.ts';
|
import { Audio } from './audio.ts';
|
||||||
import {Vision} from './vision.ts';
|
import {Vision} from './vision.ts';
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ export type AiOptions = {
|
|||||||
embedder?: string;
|
embedder?: string;
|
||||||
/** Large language models, first is default */
|
/** Large language models, first is default */
|
||||||
llm?: Omit<LLMRequest, 'model'> & {
|
llm?: Omit<LLMRequest, 'model'> & {
|
||||||
models: {[model: string]: AnthropicConfig | OllamaConfig | OpenAiConfig};
|
models: {[model: string]: AnthropicConfig | OpenAiConfig};
|
||||||
}
|
}
|
||||||
/** OCR model: eng, eng_best, eng_fast */
|
/** OCR model: eng, eng_best, eng_fast */
|
||||||
ocr?: string;
|
ocr?: string;
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import {spawn} from 'node:child_process';
|
|||||||
import {Memory, MemoryManager} from './memory.ts';
|
import {Memory, MemoryManager} from './memory.ts';
|
||||||
|
|
||||||
export type AnthropicConfig = {proto: 'anthropic', token: string};
|
export type AnthropicConfig = {proto: 'anthropic', token: string};
|
||||||
export type OllamaConfig = {proto: 'llama', host: string};
|
|
||||||
export type OpenAiConfig = {proto: 'openai', host?: string, token: string};
|
export type OpenAiConfig = {proto: 'openai', host?: string, token: string};
|
||||||
|
|
||||||
export type LLMMessage = {
|
export type LLMMessage = {
|
||||||
@@ -95,7 +94,6 @@ class LLM {
|
|||||||
Object.entries(ai.options.llm.models).forEach(([model, config]) => {
|
Object.entries(ai.options.llm.models).forEach(([model, config]) => {
|
||||||
if(!this.defaultModel) this.defaultModel = model;
|
if(!this.defaultModel) this.defaultModel = model;
|
||||||
if(config.proto == 'anthropic') this.models[model] = new Anthropic(this.ai, config.token, model);
|
if(config.proto == 'anthropic') this.models[model] = new Anthropic(this.ai, config.token, model);
|
||||||
else if(config.proto == 'llama') this.models[model] = new OpenAi(this.ai, config.host, 'ignored', model, true);
|
|
||||||
else if(config.proto == 'openai') this.models[model] = new OpenAi(this.ai, config.host || null, config.token, model);
|
else if(config.proto == 'openai') this.models[model] = new OpenAi(this.ai, config.host || null, config.token, model);
|
||||||
});
|
});
|
||||||
this.memoryManager = new MemoryManager(this);
|
this.memoryManager = new MemoryManager(this);
|
||||||
@@ -429,9 +427,8 @@ ${relevant[0].content}
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addModel(name: string, config: AnthropicConfig | OllamaConfig | OpenAiConfig, setDefault = false) {
|
addModel(name: string, config: AnthropicConfig | OpenAiConfig, setDefault = false) {
|
||||||
if(config.proto == 'anthropic') this.models[name] = new Anthropic(this.ai, config.token, name);
|
if(config.proto == 'anthropic') this.models[name] = new Anthropic(this.ai, config.token, name);
|
||||||
else if(config.proto == 'llama') this.models[name] = new OpenAi(this.ai, config.host, 'not-needed', name, true);
|
|
||||||
else if(config.proto == 'openai') this.models[name] = new OpenAi(this.ai, config.host || null, config.token, name);
|
else if(config.proto == 'openai') this.models[name] = new OpenAi(this.ai, config.host || null, config.token, name);
|
||||||
if(setDefault || !this.defaultModel) this.defaultModel = name;
|
if(setDefault || !this.defaultModel) this.defaultModel = name;
|
||||||
}
|
}
|
||||||
@@ -443,12 +440,11 @@ ${relevant[0].content}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setModels(models: {[model: string]: AnthropicConfig | OllamaConfig | OpenAiConfig}, replace = true) {
|
setModels(models: {[model: string]: AnthropicConfig | OpenAiConfig}, replace = true) {
|
||||||
if(replace) this.models = {};
|
if(replace) this.models = {};
|
||||||
Object.entries(models).forEach(([model, config]) => {
|
Object.entries(models).forEach(([model, config]) => {
|
||||||
if(!this.defaultModel) this.defaultModel = model;
|
if(!this.defaultModel) this.defaultModel = model;
|
||||||
if(config.proto == 'anthropic') this.models[model] = new Anthropic(this.ai, config.token, model);
|
if(config.proto == 'anthropic') this.models[model] = new Anthropic(this.ai, config.token, model);
|
||||||
else if(config.proto == 'llama') this.models[model] = new OpenAi(this.ai, config.host, 'not-needed', model, true);
|
|
||||||
else if(config.proto == 'openai') this.models[model] = new OpenAi(this.ai, config.host || null, config.token, model);
|
else if(config.proto == 'openai') this.models[model] = new OpenAi(this.ai, config.host || null, config.token, model);
|
||||||
});
|
});
|
||||||
this.defaultModel = Object.keys(this.models)[0] ?? '';
|
this.defaultModel = Object.keys(this.models)[0] ?? '';
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {convertSchema} from './tools.ts';
|
|||||||
export class OpenAi extends LLMProvider {
|
export class OpenAi extends LLMProvider {
|
||||||
client!: openAI;
|
client!: openAI;
|
||||||
|
|
||||||
constructor(public readonly ai: Ai, public readonly host: string | null, public readonly token: string, public model: string, public llama?: boolean) {
|
constructor(public readonly ai: Ai, public readonly host: string | null, public readonly token: string, public model: string) {
|
||||||
super();
|
super();
|
||||||
this.client = new openAI(clean({
|
this.client = new openAI(clean({
|
||||||
baseURL: host,
|
baseURL: host,
|
||||||
@@ -96,22 +96,14 @@ export class OpenAi extends LLMProvider {
|
|||||||
|
|
||||||
if(options.schema) {
|
if(options.schema) {
|
||||||
const schema = convertSchema(options.schema);
|
const schema = convertSchema(options.schema);
|
||||||
if(this.llama) {
|
requestParams.response_format = {
|
||||||
delete requestParams.tools;
|
type: 'json_schema',
|
||||||
requestParams.response_format = {
|
json_schema: {
|
||||||
type: 'json_schema',
|
name: 'response',
|
||||||
json_schema: {name: 'json', schema}
|
strict: true,
|
||||||
|
schema
|
||||||
}
|
}
|
||||||
} else {
|
};
|
||||||
requestParams.response_format = {
|
|
||||||
type: 'json_schema',
|
|
||||||
json_schema: {
|
|
||||||
name: 'response',
|
|
||||||
strict: true,
|
|
||||||
schema
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let resp: any, isFirstMessage = true;
|
let resp: any, isFirstMessage = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user