-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Base tests. Default GPT-4. Fix assistant create.
- Loading branch information
1 parent
524269c
commit 2695de3
Showing
12 changed files
with
188 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
* Remove the Assistant#messages. Is even `Message` needed? | ||
* Create a GitHub Publish Action | ||
* Add Contributors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
npm install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
export NODE_OPTIONS='--no-warnings --experimental-vm-modules' | ||
|
||
npx jest --runInBand $1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { Thread } from "./experts/thread.js"; | ||
export { Assistant } from "./experts/assistant.js"; | ||
export { Tool } from "./experts/tool.js"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { | ||
helperThreadID, | ||
helperDeleteAllAssistants, | ||
helperFindAssistant, | ||
} from "../helpers.js"; | ||
import { Assistant } from "../../src/experts/assistant.js"; | ||
|
||
const NAME = "Experts.js (Test)"; | ||
|
||
beforeEach(async () => { | ||
await helperDeleteAllAssistants(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await helperDeleteAllAssistants(); | ||
}); | ||
|
||
test("can ask the assistant a question using a thread id", async () => { | ||
const assistant = await Assistant.create( | ||
NAME, | ||
"echo", | ||
"echo the same text back to the user" | ||
); | ||
const threadID = await helperThreadID(); | ||
const output = await assistant.ask("hello 123", threadID); | ||
expect(output).toBe("hello 123"); | ||
}); | ||
|
||
test("can override defaults such as temperature and top_p", async () => { | ||
const assistant = await Assistant.create( | ||
NAME, | ||
"test-description", | ||
"test-instructions", | ||
{ temperature: 0.5, top_p: 0.5 } | ||
); | ||
expect(assistant.temperature).toBe(0.5); | ||
expect(assistant.top_p).toBe(0.5); | ||
}); | ||
|
||
test("create new assistant using name, description, and instruction defaults", async () => { | ||
// None exists before creation. | ||
const assistantNone = await helperFindAssistant(NAME); | ||
expect(assistantNone).toBeUndefined(); | ||
const assistant = await Assistant.create( | ||
NAME, | ||
"test-description", | ||
"test-instructions" | ||
); | ||
const backendAssistant = await helperFindAssistant(NAME); | ||
// Assistant | ||
expect(assistant.agentName).toBe(NAME); | ||
expect(assistant.description).toBe("test-description"); | ||
expect(assistant.instructions).toBe("test-instructions"); | ||
expect(assistant.llm).toBe(true); | ||
expect(assistant.model).toBe("gpt-4-turbo"); | ||
expect(assistant.temperature).toBe(1.0); | ||
expect(assistant.id).toMatch(/^asst_/); | ||
expect(assistant.id).toBe(backendAssistant.id); | ||
// Backend | ||
expect(backendAssistant).toBeDefined(); | ||
expect(backendAssistant.name).toBe(NAME); | ||
expect(backendAssistant.description).toBe("test-description"); | ||
expect(backendAssistant.instructions).toBe("test-instructions"); | ||
expect(backendAssistant.model).toBe("gpt-4-turbo"); | ||
expect(backendAssistant.temperature).toBe(1.0); | ||
expect(backendAssistant.id).toMatch(/^asst_/); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { openai } from "../src/openai.js"; | ||
|
||
const helperThreadID = async () => { | ||
const thread = await openai.beta.threads.create(); | ||
return thread.id; | ||
}; | ||
|
||
const helperFindAllAssistants = async () => { | ||
const assistants = await openai.beta.assistants.list({ limit: 100 }); | ||
return assistants.data.filter((a) => a.name?.startsWith("Experts.js")); | ||
}; | ||
|
||
const helperDeleteAllAssistants = async () => { | ||
const assistants = await helperFindAllAssistants(); | ||
for (const assistant of assistants) { | ||
try { | ||
await openai.beta.assistants.del(assistant.id); | ||
} catch (error) {} | ||
} | ||
}; | ||
|
||
const helperFindAssistant = async (name) => { | ||
const assistant = ( | ||
await openai.beta.assistants.list({ limit: 100 }) | ||
).data.find((a) => a.name === name); | ||
return assistant; | ||
}; | ||
|
||
const helperDeleteAssistant = async (name) => { | ||
const assistant = await helperFindAssistant(name); | ||
if (assistant !== undefined) { | ||
await openai.beta.assistants.del(assistant.id); | ||
} | ||
}; | ||
|
||
export { | ||
helperThreadID, | ||
helperFindAllAssistants, | ||
helperDeleteAllAssistants, | ||
helperFindAssistant, | ||
helperDeleteAssistant, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { helperDeleteAllAssistants } from "./helpers.js"; | ||
import { Thread, Assistant, Tool } from "../src/index.js"; | ||
|
||
const NAME = "Experts.js (Test)"; | ||
|
||
beforeEach(async () => { | ||
await helperDeleteAllAssistants(); | ||
}); | ||
|
||
afterEach(async () => { | ||
await helperDeleteAllAssistants(); | ||
}); | ||
|
||
test("can import Thread", async () => { | ||
const thread = await Thread.create(); | ||
expect(thread.id).toMatch(/^thread_/); | ||
}); | ||
|
||
test("can import Assistant", async () => { | ||
const assistant = await Assistant.create( | ||
NAME, | ||
"test-description", | ||
"test-instructions" | ||
); | ||
expect(assistant.id).toMatch(/^asst_/); | ||
}); | ||
|
||
test("can import Tool", async () => { | ||
const tool = await Tool.create( | ||
NAME, | ||
"test-description", | ||
"test-instructions", | ||
{ llm: false } | ||
); | ||
expect(tool.isTool).toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { openai } from "../src/openai.js"; | ||
|
||
test("exports an openai client", () => { | ||
expect(openai).toBeInstanceOf(Object); | ||
expect(openai.beta).toBeInstanceOf(Object); | ||
expect(openai.beta.threads).toBeInstanceOf(Object); | ||
}); |