Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b814ea8b28 | |||
| 06dda88dbc |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/ai-utils",
|
"name": "@ztimson/ai-utils",
|
||||||
"version": "0.8.7",
|
"version": "0.8.9",
|
||||||
"description": "AI Utility library",
|
"description": "AI Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
@@ -117,12 +117,13 @@ class LLM {
|
|||||||
const score = (o ? this.cosineSimilarity(m.embeddings[0], o[0].embedding) : 0)
|
const score = (o ? this.cosineSimilarity(m.embeddings[0], o[0].embedding) : 0)
|
||||||
+ (q ? this.cosineSimilarity(m.embeddings[1], q[0].embedding) : 0);
|
+ (q ? this.cosineSimilarity(m.embeddings[1], q[0].embedding) : 0);
|
||||||
return {...m, score};
|
return {...m, score};
|
||||||
}).toSorted((a: any, b: any) => a.score - b.score).slice(0, limit);
|
}).toSorted((a: any, b: any) => a.score - b.score).slice(0, limit)
|
||||||
|
.map(m => `- ${m.owner}: ${m.fact}`).join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
options.system += '\nYou have RAG memory and will be given the top_k closest memories regarding the users query. Save anything new you have learned worth remembering from the user message using the remember tool and feel free to recall memories manually.\n';
|
options.system += '\nYou have RAG memory and will be given the top_k closest memories regarding the users query. Save anything new you have learned worth remembering from the user message using the remember tool and feel free to recall memories manually.\n';
|
||||||
const relevant = await search(message);
|
const relevant = await search(message);
|
||||||
if(relevant.length) options.history.push({role: 'tool', name: 'recall', id: 'auto_recall_' + Math.random().toString(), args: {}, content: 'Things I remembered:\n' + relevant.map(m => `${m.owner}: ${m.fact}`).join('\n')});
|
if(relevant.length) options.history.push({role: 'tool', name: 'recall', id: 'auto_recall_' + Math.random().toString(), args: {}, content: `Things I remembered:\n${relevant}`});
|
||||||
options.tools = [{
|
options.tools = [{
|
||||||
name: 'recall',
|
name: 'recall',
|
||||||
description: 'Recall the closest memories you have regarding a query using RAG',
|
description: 'Recall the closest memories you have regarding a query using RAG',
|
||||||
|
|||||||
@@ -148,7 +148,6 @@ export class OpenAi extends LLMProvider {
|
|||||||
try {
|
try {
|
||||||
const args = JSONAttemptParse(toolCall.function.arguments, {});
|
const args = JSONAttemptParse(toolCall.function.arguments, {});
|
||||||
const result = await tool.fn(args, options.stream, this.ai);
|
const result = await tool.fn(args, options.stream, this.ai);
|
||||||
console.log(result);
|
|
||||||
return {role: 'tool', tool_call_id: toolCall.id, content: JSONSanitize(result)};
|
return {role: 'tool', tool_call_id: toolCall.id, content: JSONSanitize(result)};
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
return {role: 'tool', tool_call_id: toolCall.id, content: JSONSanitize({error: err?.message || err?.toString() || 'Unknown'})};
|
return {role: 'tool', tool_call_id: toolCall.id, content: JSONSanitize({error: err?.message || err?.toString() || 'Unknown'})};
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ export const JSTool: AiTool = {
|
|||||||
code: {type: 'string', description: 'CommonJS javascript', required: true}
|
code: {type: 'string', description: 'CommonJS javascript', required: true}
|
||||||
},
|
},
|
||||||
fn: async (args: {code: string}) => {
|
fn: async (args: {code: string}) => {
|
||||||
console.log('executing js')
|
|
||||||
const c = consoleInterceptor(null);
|
const c = consoleInterceptor(null);
|
||||||
const resp = await Fn<any>({console: c}, args.code, true).catch((err: any) => c.output.error.push(err));
|
const resp = await Fn<any>({console: c}, args.code, true).catch((err: any) => c.output.error.push(err));
|
||||||
return {...c.output, return: resp, stdout: undefined, stderr: undefined};
|
return {...c.output, return: resp, stdout: undefined, stderr: undefined};
|
||||||
|
|||||||
Reference in New Issue
Block a user