Skip to content
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: convert tool call schemas between providers #5206

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

cephalization
Copy link
Contributor

@cephalization cephalization commented Oct 28, 2024

TODO:

  • Write openai schema and conversions
  • Write anthropic schema and conversions
  • Convert tool calls in playground when user switches provider
  • Tests

Resolves #5100

@cephalization cephalization force-pushed the cephalization/5100-tool-json-schema-zod-utils branch from 4be2451 to bf06457 Compare October 28, 2024 18:01
* allow for extra keys when the zod schema is used for parsing. This is to allow more flexibility for users
* to define their own tool calls according
*/
export const openAIToolCallSchema = z.object({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should replace the one in your playground/toolCallSchemas file above right?

*/
export const detectProvider = (
toolCall: unknown
): { provider: ModelProvider; validatedToolCall: AnyToolCall } => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you constrain this type so that it's

Suggested change
): { provider: ModelProvider; validatedToolCall: AnyToolCall } => {
): { provider: 'OPENAI'; validatedToolCall: OpenAIToolCall } | Anthrpic stuff => {

does that help, seems like it would reduce casting below but would make the return type very unwieldy and hard to maintain

};

export const toOpenAIFormat = (toolCall: AnyToolCall): OpenAIToolCall => {
const { provider, validatedToolCall } = detectProvider(toolCall);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes like this much more than the casting up above

Copy link
Contributor

@Parker-Stafford Parker-Stafford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really awesome, seems very ergonomic for the difficulty of the transformations, ignore comments in playground/toolCallSchemas since that is going away correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 📘 Todo
Development

Successfully merging this pull request may close these issues.

[playground] tool JSON schema utils (anthropic -> open_ai -> ???)
2 participants