-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(playground): add tools ui #5002
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
5985a68
feat(playground): add tools ui
Parker-Stafford 210c8e6
add tools back after rebase
Parker-Stafford 45c4187
update tool type to be partial in store for editing
Parker-Stafford de5de53
make tool editor uncontrolled, add tool choice selector
Parker-Stafford d13b22b
make fields pass through
Parker-Stafford f073b53
allow for extra keys in the json schema
Parker-Stafford 466a2f4
support json schema in jsonEditor, remove jsonToolEditor
Parker-Stafford aca7a68
update descriptions
Parker-Stafford 2e2ad84
fix types
Parker-Stafford b777bf0
fix key collision on choice picker
Parker-Stafford 0b9f551
update comment
Parker-Stafford 8c1642b
more comments
Parker-Stafford bedd86b
WIP
mikeldking 44b477f
styling
mikeldking 0f0173b
cleanup
mikeldking File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Large diffs are not rendered by default.
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,102 @@ | ||
import React from "react"; | ||
|
||
import { Flex, Item, Label, Picker } from "@arizeai/components"; | ||
|
||
type DefaultToolChoice = Extract<ToolChoice, "auto" | "required" | "none">; | ||
|
||
const isDefaultToolChoice = (choice: string): choice is DefaultToolChoice => { | ||
return choice === "auto" || choice === "required" || choice === "none"; | ||
}; | ||
|
||
/** | ||
* A prefix to add to user defined tools in the picker to avoid picker key collisions with default {@link ToolChoice} keys | ||
*/ | ||
const TOOL_NAME_PREFIX = "tool_"; | ||
|
||
/** | ||
* Adds a prefix to user defined tool names to avoid conflicts picker key collisions with default {@link ToolChoice} keys | ||
* @param toolName The name of a tool | ||
* @returns The tool name with the "TOOL_NAME_PREFIX" prefix added | ||
*/ | ||
const addToolNamePrefix = (toolName: string) => | ||
`${TOOL_NAME_PREFIX}${toolName}`; | ||
|
||
/** | ||
* Removes the "TOOL_NAME_PREFIX" prefix from a tool name so that it can be used as a choice that corresponds to an actual tool | ||
* @param toolName The name of a tool with the "TOOL_NAME_PREFIX" prefix | ||
* @returns The tool name with the "TOOL_NAME_PREFIX" prefix removed | ||
*/ | ||
const removeToolNamePrefix = (toolName: string) => | ||
toolName.startsWith(TOOL_NAME_PREFIX) | ||
? toolName.slice(TOOL_NAME_PREFIX.length) | ||
: toolName; | ||
|
||
type ToolChoicePickerProps = { | ||
/** | ||
* The current choice including the default {@link ToolChoice} and any user defined tools | ||
*/ | ||
choice: ToolChoice; | ||
/** | ||
* Callback for when the tool choice changes | ||
*/ | ||
onChange: (choice: ToolChoice) => void; | ||
/** | ||
* A list of user defined tool names | ||
*/ | ||
toolNames: string[]; | ||
}; | ||
|
||
export function ToolChoicePicker({ | ||
choice, | ||
onChange, | ||
toolNames, | ||
}: ToolChoicePickerProps) { | ||
const currentKey = | ||
typeof choice === "string" | ||
? choice | ||
: addToolNamePrefix(choice.function.name); | ||
return ( | ||
<Picker | ||
selectedKey={currentKey} | ||
label="Tool Choice" | ||
aria-label="Tool Choice for an LLM" | ||
onSelectionChange={(choice) => { | ||
if (typeof choice !== "string") { | ||
return; | ||
} | ||
if (choice.startsWith(TOOL_NAME_PREFIX)) { | ||
onChange({ | ||
type: "function", | ||
function: { | ||
name: removeToolNamePrefix(choice), | ||
}, | ||
}); | ||
} else if (isDefaultToolChoice(choice)) { | ||
onChange(choice); | ||
} | ||
}} | ||
> | ||
{[ | ||
<Item key="auto"> | ||
<Flex gap={"size-100"}> | ||
Tools auto-selected by LLM <Label>auto</Label> | ||
</Flex> | ||
</Item>, | ||
<Item key="required"> | ||
<Flex gap={"size-100"}> | ||
Use at least one tool <Label>required</Label> | ||
</Flex> | ||
</Item>, | ||
<Item key="none"> | ||
<Flex gap={"size-100"}> | ||
Don't use any tools <Label>none</Label> | ||
</Flex> | ||
</Item>, | ||
// Add "TOOL_NAME_PREFIX" prefix to user defined tool names to avoid conflicts with default keys | ||
...toolNames.map((toolName) => ( | ||
<Item key={addToolNamePrefix(toolName)}>{toolName}</Item> | ||
)), | ||
]} | ||
</Picker> | ||
); | ||
} |
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 @@ | ||
export * from "./ToolChoiceSelector"; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the 7 here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the version of the json schema spec i believe