Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7dd3307a07 |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/ai-utils",
|
"name": "@ztimson/ai-utils",
|
||||||
"version": "1.0.1",
|
"version": "1.0.2",
|
||||||
"description": "AI Utility library",
|
"description": "AI Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
25
src/llm.ts
25
src/llm.ts
@@ -458,6 +458,31 @@ class LLM {
|
|||||||
if(!done) reject(`AI failed to create summary:\n${resp}`);
|
if(!done) reject(`AI failed to create summary:\n${resp}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addModel(name: string, config: AnthropicConfig | OllamaConfig | OpenAiConfig, setDefault = false) {
|
||||||
|
if(config.proto == 'anthropic') this.models[name] = new Anthropic(this.ai, config.token, name);
|
||||||
|
else if(config.proto == 'ollama') this.models[name] = new OpenAi(this.ai, config.host, 'not-needed', 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
removeModel(name: string) {
|
||||||
|
delete this.models[name];
|
||||||
|
if(this.defaultModel === name) {
|
||||||
|
this.defaultModel = Object.keys(this.models)[0] ?? '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setModels(models: {[model: string]: AnthropicConfig | OllamaConfig | OpenAiConfig}, replace = true) {
|
||||||
|
if(replace) this.models = {};
|
||||||
|
Object.entries(models).forEach(([model, config]) => {
|
||||||
|
if(!this.defaultModel) this.defaultModel = model;
|
||||||
|
if(config.proto == 'anthropic') this.models[model] = new Anthropic(this.ai, config.token, model);
|
||||||
|
else if(config.proto == 'ollama') this.models[model] = new OpenAi(this.ai, config.host, 'not-needed', 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] ?? '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default LLM;
|
export default LLM;
|
||||||
|
|||||||
Reference in New Issue
Block a user