Skip to content

Commit

Permalink
Use Assistant.create() pattern. Refactor test cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
metaskills committed Apr 29, 2024
1 parent fdb6851 commit c158024
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 53 deletions.
7 changes: 3 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

* Change `init` to `create`.
* Create a beforeInit event/hook vs. an override.
* Can citations be removed from vector store QnA?
* Make sure assistant find by id works using something like a `process.env.ID`
* Make sure the assistant find by id works using something like a `process.env.ID`
* Remove the Assistant#messages. Is even `Message` needed?
* TODO: Revist this and assistantsToolsOutputs.
* Test 2 panel split knowledge. Test the default tool using its thread.
* TODO: Revisit this and assistantsToolsOutputs.
* Add Contributors
2 changes: 1 addition & 1 deletion jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default {
transform: {},
testMatch: ["<rootDir>/test/**/*.test.js"],
globalSetup: "./test/globalSetup.js",
globalTeardown: undefined,
globalTeardown: "./test/globalTeardown.js",
slowTestThreshold: 30,
cacheDirectory: "./tmp",
setupFiles: [],
Expand Down
2 changes: 1 addition & 1 deletion src/experts/assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Message } from "./messages.js";
import { Run } from "./run.js";

class Assistant {
static async init() {
static async create() {
const asst = new this();
await asst.init();
return asst;
Expand Down
24 changes: 3 additions & 21 deletions test/experts/assistant.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,17 @@ import {
helperName,
helperPath,
helperThreadID,
helperDeleteAllAssistants,
helperFindAssistant,
helperDeleteAllVectorStores,
} from "../helpers.js";
import {
TestAssistant,
EchoAssistant,
OddFactsAssistant,
} from "../fixtures.js";

beforeEach(async () => {
await helperDeleteAllAssistants();
});

afterEach(async () => {
await helperDeleteAllAssistants();
});

describe("with vector store", () => {
beforeEach(async () => {
await helperDeleteAllVectorStores();
});

afterEach(async () => {
await helperDeleteAllVectorStores();
});

test("can provide tools", async () => {
const assistant = await OddFactsAssistant.init();
const assistant = await OddFactsAssistant.create();
const threadID = await helperThreadID();
const output = await assistant.ask(
"Using a single word response, tell me what food source do Proxima Centauri b inhabitants migrate for?",
Expand All @@ -43,7 +25,7 @@ describe("with vector store", () => {
});

test("can ask the assistant a question using a thread id", async () => {
const assistant = await EchoAssistant.init();
const assistant = await EchoAssistant.create();
const threadID = await helperThreadID();
const output = await assistant.ask("hello 123", threadID);
expect(output).toBe("hello 123");
Expand Down Expand Up @@ -81,7 +63,7 @@ test("create new assistant using name, description, and instruction defaults", a
TestAssistant.name = name;
const assistantNone = await helperFindAssistant(name);
expect(assistantNone).toBeUndefined();
const assistant = await TestAssistant.init();
const assistant = await TestAssistant.create();
const backendAssistant = await helperFindAssistant(name);
// Assistant
expect(assistant.agentName).toBe(name);
Expand Down
6 changes: 1 addition & 5 deletions test/experts/thread.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
helperThreadID,
helperDeleteAllAssistants,
helperFindAssistant,
} from "../helpers.js";
import { helperThreadID, helperFindAssistant } from "../helpers.js";

import { Thread } from "../../src/experts/thread.js";

Expand Down
19 changes: 10 additions & 9 deletions test/experts/tool.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { helperDeleteAllAssistants, helperThreadID } from "../helpers.js";
import { DataTool } from "../fixtures.js";
import { helperThreadID } from "../helpers.js";
import { EchoTool, DataTool } from "../fixtures.js";

beforeEach(async () => {
await helperDeleteAllAssistants();
});

afterEach(async () => {
await helperDeleteAllAssistants();
test("simple echo tool", async () => {
const tool = await EchoTool.create();
expect(tool.isTool).toBe(true);
const threadID = await helperThreadID();
const output = await tool.ask("hello 123", threadID);
expect(output).toMatch("hello 123");
});

test("simple qa with a CSV data tool", async () => {
const tool = await DataTool.init();
const tool = await DataTool.create();
expect(tool.isTool).toBe(true);
const threadID = await helperThreadID();
const output = await tool.ask(
"What is the name of the fourth person in the data?",
Expand Down
1 change: 1 addition & 0 deletions test/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { EchoAssistant } from "./fixtures/echoAssistant.js";
export { OddFactsAssistant } from "./fixtures/oddFactsAssistant.js";
export { TestAssistant } from "./fixtures/testAssistant.js";
export { DataTool } from "./fixtures/dataTool.js";
export { EchoTool } from "./fixtures/echoTool.js";
13 changes: 13 additions & 0 deletions test/fixtures/echoTool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { helperName } from "../helpers.js";
import { Tool } from "../../src/experts/tool.js";

class EchoTool extends Tool {
constructor() {
const name = helperName("EchoTool");
const description = "Echo";
const instructions = "Echo the same text back to the user";
super(name, description, instructions);
}
}

export { EchoTool };
11 changes: 8 additions & 3 deletions test/globalSetup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
process.env.NODE_ENV = "test";

// import _ from "lodash";
// global._ = _;
import {
helperDeleteAllAssistants,
helperDeleteAllVectorStores,
} from "./helpers.js";

export default function () {}
export default async function () {
await helperDeleteAllAssistants();
await helperDeleteAllVectorStores();
}
9 changes: 9 additions & 0 deletions test/globalTeardown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import {
helperDeleteAllAssistants,
helperDeleteAllVectorStores,
} from "./helpers.js";

export default async function () {
await helperDeleteAllAssistants();
await helperDeleteAllVectorStores();
}
10 changes: 1 addition & 9 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { helperName, helperDeleteAllAssistants } from "./helpers.js";
import { helperName } from "./helpers.js";
import { Thread, Assistant, Tool } from "../src/index.js";

beforeEach(async () => {
await helperDeleteAllAssistants();
});

afterEach(async () => {
await helperDeleteAllAssistants();
});

test("can import Thread", async () => {
const thread = await Thread.create();
expect(thread.id).toMatch(/^thread_/);
Expand Down

0 comments on commit c158024

Please sign in to comment.