-
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.
Demonstrate Function Calling & Structured Outputs with Zod
- Loading branch information
1 parent
cef8794
commit ef54d18
Showing
6 changed files
with
86 additions
and
3 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { helperName } from "../helpers.js"; | ||
import { Tool } from "../../src/experts/tool.js"; | ||
import { Assistant } from "../../src/experts/assistant.js"; | ||
import { z } from "zod"; | ||
import { zodFunction, zodResponseFormat } from "openai/helpers/zod"; | ||
|
||
class IdeogramTool extends Tool { | ||
constructor() { | ||
super({ | ||
name: helperName("IdeogramTool"), | ||
model: "gpt-4o-2024-08-06", | ||
instructions: | ||
"Turn an ideaogram concept into an Ideogram prompt. Very short paragraph.", | ||
temperature: 0.1, | ||
asyncRun: true, | ||
parentsTools: [ | ||
zodFunction({ | ||
name: "ideogram", | ||
description: "Submit a single concept to cerate an ideogram prompt", | ||
parameters: z.object({ | ||
concept: z.object({ | ||
concept: z | ||
.string() | ||
.describe("Brief concept in a single sentence."), | ||
thinking: z | ||
.string() | ||
.describe("Your detailed thinking behind the concept."), | ||
}), | ||
}), | ||
}), | ||
], | ||
response_format: zodResponseFormat( | ||
z.object({ prompt: z.string() }), | ||
"prompt" | ||
), | ||
}); | ||
} | ||
} | ||
|
||
class CreativeAssistant extends Assistant { | ||
constructor() { | ||
super({ | ||
name: helperName("CreativeAssistant"), | ||
model: "gpt-4o-2024-08-06", | ||
instructions: | ||
"Take a topic and use your ideogram tool to create three concepts.", | ||
temperature: 0.1, | ||
response_format: zodResponseFormat( | ||
z.object({ prompts: z.array(z.object({ prompt: z.string() })) }), | ||
"prompt" | ||
), | ||
}); | ||
this.addAssistantTool(IdeogramTool); | ||
} | ||
} | ||
|
||
export { CreativeAssistant }; |
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,13 @@ | ||
import { helperThreadID } from "../helpers.js"; | ||
import { CreativeAssistant } from "../fixtures.js"; | ||
|
||
// TODO: Allow these tool calls to be async with a unique thread. | ||
|
||
test("can call 3 tools in sequence", async () => { | ||
const threadID = await helperThreadID(); | ||
const assistant = await CreativeAssistant.create(); | ||
await assistant.ask( | ||
"RouteLLM: What it is and what you should know.", | ||
threadID | ||
); | ||
}, 60000); |