-
Notifications
You must be signed in to change notification settings - Fork 3.6k
feat: support tool-level provider options in OpenAI-compatible provider #11505
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
base: main
Are you sure you want to change the base?
feat: support tool-level provider options in OpenAI-compatible provider #11505
Conversation
- Add getToolMetadata() helper function to extract providerOptions from tools - Spread tool-level provider options into prepared tools for API requests - Update return type to support additional metadata fields via Record<string, unknown> - Add comprehensive tests for tool-level providerOptions support - Tests follow the same pattern as message-level provider options in convert-to-openai-compatible-chat-messages.test.ts Note: Currently uses the hardcoded 'openaiCompatible' key pattern to maintain consistency with message-level conversion behavior. Dynamic provider names for both message and tool options should be addressed in a future refactoring.
…ions in OpenAI-compatible provider
6080a26 to
ad5241d
Compare
| function getToolMetadata(tool: { providerOptions?: SharedV3ProviderMetadata }) { | ||
| return tool?.providerOptions?.openaiCompatible ?? {}; | ||
| } |
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.
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.
I had this initially, but then I noticed that we already have some inconsistencies in this regard. I decided to stick to what we are doing in the packages/openai-compatible/src/chat/convert-to-openai-compatible-chat-messages.ts.
ai/packages/openai-compatible/src/chat/convert-to-openai-compatible-chat-messages.ts
Line 12 in 98d480e
| return message?.providerOptions?.openaiCompatible ?? {}; |
That being said it would be better to pass the provider name like you suggested.
- Shall I update the
packages/openai-compatible/src/chat/convert-to-openai-compatible-chat-messages.tsandpackages/openai-compatible/src/chat/openai-compatible-prepare-tools.tsto use the provider name? - For the
packages/openai-compatible/src/chat/convert-to-openai-compatible-chat-messages.ts, shall I use a fallback to theopenaiCompatible, as consumers might have already integrated with this key?
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.
It should be consistent. I would suggest a separate PR that cleans out the current behavior 1st and makes it consistent. That way we we can focus first on consistency and think about backwards compat, testing, etc. Once that lands we can continue with this PR. Would you be interested in taking this on?
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.
Sounds good to me, will tag you once it's ready.

Summary
This PR adds support for tool-level provider options in the OpenAI-compatible provider. Tools can now include custom provider metadata through the
providerOptionsfield, which gets properly merged into the prepared tools for API requests.Changes Made
prepareToolsfunction to extract and merge tool-level metadata fromproviderOptions.openaiCompatible