-
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: convert tool call schemas between providers #5206
base: main
Are you sure you want to change the base?
Conversation
4be2451
to
bf06457
Compare
* 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({ |
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.
this should replace the one in your playground/toolCallSchemas file above right?
*/ | ||
export const detectProvider = ( | ||
toolCall: unknown | ||
): { provider: ModelProvider; validatedToolCall: AnyToolCall } => { |
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.
could you constrain this type so that it's
): { 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); |
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.
yes like this much more than the casting up above
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.
this is really awesome, seems very ergonomic for the difficulty of the transformations, ignore comments in playground/toolCallSchemas since that is going away correct?
TODO:
Resolves #5100