-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from metaskills/RunOptions
Add Run Options. Fixes #7.
- Loading branch information
Showing
8 changed files
with
145 additions
and
11 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,53 @@ | ||
import { helperName } from "../helpers.js"; | ||
import { Assistant, Tool } from "../../src/index.js"; | ||
|
||
class DrillTool extends Tool { | ||
static calls = 0; | ||
constructor() { | ||
const name = helperName("DrillTool"); | ||
const description = "A drill tool."; | ||
super(name, description, "", { | ||
llm: false, | ||
parentsTools: [ | ||
{ | ||
type: "function", | ||
function: { | ||
name: DrillTool.toolName, | ||
description: description, | ||
parameters: { | ||
type: "object", | ||
properties: { use: { type: "boolean" } }, | ||
required: ["use"], | ||
}, | ||
}, | ||
}, | ||
], | ||
}); | ||
} | ||
|
||
async ask(_message) { | ||
this.constructor.calls += 1; | ||
return "The drill started working again. I drilled a hole in the wall so we can punch through to the other side. It was very loud, did you hear it?"; | ||
} | ||
} | ||
|
||
class CarpenterAssistant extends Assistant { | ||
constructor() { | ||
const name = helperName("Carpenter"); | ||
const description = "A carpenter that does not work."; | ||
const instructions = | ||
"Avoid work at all costs because your drill is broken. But if you did do work, tell me what you did."; | ||
super(name, description, instructions, { | ||
temperature: 0.1, | ||
run_options: { | ||
tool_choice: { | ||
type: "function", | ||
function: { name: DrillTool.toolName }, | ||
}, | ||
}, | ||
}); | ||
this.addAssistantTool(DrillTool); | ||
} | ||
} | ||
|
||
export { CarpenterAssistant, DrillTool }; |
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 { CarpenterAssistant, DrillTool } from "../fixtures/toolboxAssistant.js"; | ||
|
||
test("an assistant with run_options or using run options to ask", async () => { | ||
const assistant = await CarpenterAssistant.create(); | ||
const threadID = await helperThreadID(); | ||
const output = await assistant.ask("start work", threadID); | ||
expect(DrillTool.calls).toBe(1); | ||
expect(output).toMatch(/hole.*wall/); | ||
const output2 = await assistant.ask("are you done?", threadID, { | ||
run: { | ||
additional_instructions: | ||
"The job is done! You would like to get paid. Ask for $200.", | ||
}, | ||
}); | ||
expect(output2).toMatch(/200/); | ||
}); |