-
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.
- Loading branch information
1 parent
1be58e9
commit 53e84c0
Showing
15 changed files
with
145 additions
and
20 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
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,2 @@ | ||
|
||
* Add a buffered output tool (append, prepend) to support bespoke user interfaces. |
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
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,72 @@ | ||
import { Tool } from "../../src/experts/tool.js"; | ||
import { Assistant } from "../../src/experts/assistant.js"; | ||
|
||
class AccountsTool extends Tool { | ||
constructor() { | ||
super({ | ||
llm: false, | ||
parentsTools: [ | ||
{ | ||
type: "function", | ||
function: { | ||
name: "accounts_find_by_id", | ||
description: "Find an account by ID", | ||
parameters: { | ||
type: "object", | ||
properties: { id: { type: "integer" } }, | ||
required: ["id"], | ||
}, | ||
}, | ||
}, | ||
{ | ||
type: "function", | ||
function: { | ||
name: "accounts_find_by_email", | ||
description: "Find an account by Email", | ||
parameters: { | ||
type: "object", | ||
properties: { email: { type: "string" } }, | ||
required: ["email"], | ||
}, | ||
}, | ||
}, | ||
], | ||
}); | ||
} | ||
|
||
async ask(message) { | ||
const params = JSON.parse(message); | ||
if (params.id) { | ||
return this.#findByID(params.id); | ||
} else if (params.email) { | ||
return this.#findByEmail(params.email); | ||
} | ||
} | ||
|
||
#findByID(id) { | ||
return JSON.stringify({ | ||
id: id, | ||
email: "[email protected]", | ||
name: "Jordan Whitaker", | ||
}); | ||
} | ||
|
||
#findByEmail(email) { | ||
return JSON.stringify({ | ||
id: 838282, | ||
email: email, | ||
name: "Elena Prescott", | ||
}); | ||
} | ||
} | ||
|
||
class AccountsAssistant extends Assistant { | ||
constructor() { | ||
super({ | ||
instructions: "Routes messages to the right tool.", | ||
}); | ||
this.addAssistantTool(AccountsTool); | ||
} | ||
} | ||
|
||
export { AccountsAssistant, AccountsTool }; |
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
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
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,17 @@ | ||
import { helperThreadID } from "../helpers.js"; | ||
import { AccountsAssistant } from "../fixtures.js"; | ||
|
||
test("can find an expert that has many tools", async () => { | ||
const assistant = await AccountsAssistant.create(); | ||
const threadID = await helperThreadID(); | ||
const output = await assistant.ask( | ||
"What is the name of the user with an id of 32916?", | ||
threadID | ||
); | ||
expect(output).toMatch(/Jordan Whitaker/i); | ||
const output2 = await assistant.ask( | ||
"What is the name of the user with email of [email protected]?", | ||
threadID | ||
); | ||
expect(output2).toMatch(/Elena Prescott/i); | ||
}, 20000); |