Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6454548364 | |||
| 936317f2f2 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/ai-utils",
|
||||
"version": "0.8.4",
|
||||
"version": "0.8.6",
|
||||
"description": "AI Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
||||
@@ -151,7 +151,7 @@ class LLM {
|
||||
const newMem = {owner: args.owner, fact: args.fact, embeddings: <any>[e[0][0].embedding, e[1][0].embedding]};
|
||||
options.memory.splice(0, options.memory.length, ...[
|
||||
...options.memory.filter(m => {
|
||||
return this.cosineSimilarity(newMem.embeddings[0], m.embeddings[0]) < 0.9 && this.cosineSimilarity(newMem.embeddings[1], m.embeddings[1]) < 0.8;
|
||||
return !(this.cosineSimilarity(newMem.embeddings[0], m.embeddings[0]) >= 0.9 && this.cosineSimilarity(newMem.embeddings[1], m.embeddings[1]) >= 0.8);
|
||||
}),
|
||||
newMem
|
||||
]);
|
||||
|
||||
14
src/tools.ts
14
src/tools.ts
@@ -1,9 +1,15 @@
|
||||
import * as cheerio from 'cheerio';
|
||||
import {$, $Sync} from '@ztimson/node-utils';
|
||||
import {$Sync} from '@ztimson/node-utils';
|
||||
import {ASet, consoleInterceptor, Http, fn as Fn} from '@ztimson/utils';
|
||||
import * as os from 'node:os';
|
||||
import {Ai} from './ai.ts';
|
||||
import {LLMRequest} from './llm.ts';
|
||||
|
||||
const getShell = () => {
|
||||
if(os.platform() == 'win32') return 'cmd';
|
||||
return $Sync`echo $SHELL`?.split('/').pop() || 'bash';
|
||||
}
|
||||
|
||||
export type AiToolArg = {[key: string]: {
|
||||
/** Argument type */
|
||||
type: 'array' | 'boolean' | 'number' | 'object' | 'string',
|
||||
@@ -40,7 +46,7 @@ export const CliTool: AiTool = {
|
||||
name: 'cli',
|
||||
description: 'Use the command line interface, returns any output',
|
||||
args: {command: {type: 'string', description: 'Command to run', required: true}},
|
||||
fn: (args: {command: string}) => $`${args.command}`
|
||||
fn: (args: {command: string}) => $Sync`${args.command}`
|
||||
}
|
||||
|
||||
export const DateTimeTool: AiTool = {
|
||||
@@ -54,13 +60,13 @@ export const ExecTool: AiTool = {
|
||||
name: 'exec',
|
||||
description: 'Run code/scripts',
|
||||
args: {
|
||||
language: {type: 'string', description: 'Execution language', enum: ['cli', 'node', 'python'], required: true},
|
||||
language: {type: 'string', description: `Execution language (CLI: ${getShell()})`, enum: ['cli', 'node', 'python'], required: true},
|
||||
code: {type: 'string', description: 'Code to execute', required: true}
|
||||
},
|
||||
fn: async (args, stream, ai) => {
|
||||
try {
|
||||
switch(args.type) {
|
||||
case 'bash':
|
||||
case 'cli':
|
||||
return await CliTool.fn({command: args.code}, stream, ai);
|
||||
case 'node':
|
||||
return await JSTool.fn({code: args.code}, stream, ai);
|
||||
|
||||
Reference in New Issue
Block a user