Added memory system
This commit is contained in:
11
src/tools.ts
11
src/tools.ts
@@ -2,6 +2,7 @@ import * as cheerio from 'cheerio';
|
||||
import {$, $Sync} from '@ztimson/node-utils';
|
||||
import {ASet, consoleInterceptor, Http, fn as Fn} from '@ztimson/utils';
|
||||
import {Ai} from './ai.ts';
|
||||
import {LLMRequest} from './llm.ts';
|
||||
|
||||
export type AiToolArg = {[key: string]: {
|
||||
/** Argument type */
|
||||
@@ -32,7 +33,7 @@ export type AiTool = {
|
||||
/** Tool arguments */
|
||||
args?: AiToolArg,
|
||||
/** Callback function */
|
||||
fn: (args: any, ai: Ai) => any | Promise<any>,
|
||||
fn: (args: any, stream: LLMRequest['stream'], ai: Ai) => any | Promise<any>,
|
||||
};
|
||||
|
||||
export const CliTool: AiTool = {
|
||||
@@ -56,15 +57,15 @@ export const ExecTool: AiTool = {
|
||||
language: {type: 'string', description: 'Execution language', enum: ['cli', 'node', 'python'], required: true},
|
||||
code: {type: 'string', description: 'Code to execute', required: true}
|
||||
},
|
||||
fn: async (args, ai) => {
|
||||
fn: async (args, stream, ai) => {
|
||||
try {
|
||||
switch(args.type) {
|
||||
case 'bash':
|
||||
return await CliTool.fn({command: args.code}, ai);
|
||||
return await CliTool.fn({command: args.code}, stream, ai);
|
||||
case 'node':
|
||||
return await JSTool.fn({code: args.code}, ai);
|
||||
return await JSTool.fn({code: args.code}, stream, ai);
|
||||
case 'python': {
|
||||
return await PythonTool.fn({code: args.code}, ai);
|
||||
return await PythonTool.fn({code: args.code}, stream, ai);
|
||||
}
|
||||
}
|
||||
} catch(err: any) {
|
||||
|
||||
Reference in New Issue
Block a user