Skip to content

Commit

Permalink
Simple Assistant Tool w/Router test.
Browse files Browse the repository at this point in the history
  • Loading branch information
metaskills committed Apr 29, 2024
1 parent c158024 commit f85722c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
* Remove the Assistant#messages. Is even `Message` needed?
* Test 2 panel split knowledge. Test the default tool using its thread.
* TODO: Revisit this and assistantsToolsOutputs.
* Is `addAssistantTool` the right name now?
* Add Contributors
10 changes: 10 additions & 0 deletions test/experts/assistant.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,18 @@ import {
TestAssistant,
EchoAssistant,
OddFactsAssistant,
RouterAssistant,
} from "../fixtures.js";

test("assistant as tool", async () => {
const assistant = await RouterAssistant.create();
const threadID = await helperThreadID();
const output = await assistant.ask("i need sales help", threadID);
expect(output).toMatch(/unrouteable/);
const output2 = await assistant.ask("/echo 123 hello", threadID);
expect(output2).toMatch(/123 hello/);
});

describe("with vector store", () => {
test("can provide tools", async () => {
const assistant = await OddFactsAssistant.create();
Expand Down
1 change: 1 addition & 0 deletions test/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { OddFactsAssistant } from "./fixtures/oddFactsAssistant.js";
export { TestAssistant } from "./fixtures/testAssistant.js";
export { DataTool } from "./fixtures/dataTool.js";
export { EchoTool } from "./fixtures/echoTool.js";
export { RouterAssistant } from "./fixtures/routerAssistant.js";
17 changes: 16 additions & 1 deletion test/fixtures/echoTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@ class EchoTool extends Tool {
const name = helperName("EchoTool");
const description = "Echo";
const instructions = "Echo the same text back to the user";
super(name, description, instructions);
super(name, description, instructions, {
parentsTools: [
{
type: "function",
function: {
name: EchoTool.toolName,
description: description,
parameters: {
type: "object",
properties: { message: { type: "string" } },
required: ["message"],
},
},
},
],
});
}
}

Expand Down
16 changes: 16 additions & 0 deletions test/fixtures/routerAssistant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { helperName } from "../helpers.js";
import { Assistant } from "../../src/experts/assistant.js";
import { EchoTool } from "./echoTool.js";

class RouterAssistant extends Assistant {
constructor() {
const name = helperName("Router");
const description = "Conversational Router";
const instructions =
"Routes messages to the right tool. Send any message starting with the /echo command to the echo tool. If no tool can be found for the message, reply with one word 'unrouteable' as the error.";
super(name, description, instructions);
this.addAssistantTool(EchoTool);
}
}

export { RouterAssistant };

0 comments on commit f85722c

Please sign in to comment.