-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add supportsStructuredOutputs option to OpenAI-compatible provider #8428
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
Open
michaelchiche
wants to merge
2
commits into
vercel:main
Choose a base branch
from
michaelchiche:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+8
−0
Open
Changes from all commits
Commits
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 hidden or 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 hidden or 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.
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.
The
supportsStructuredOutputs
option is not passed to completion models, creating inconsistent behavior where only chat models will respect this setting.View Details
📝 Patch Details
Analysis
OpenAI Compatible Provider Structured Outputs Inconsistency
Analysis
The OpenAI Compatible provider exhibited an inconsistency where the
supportsStructuredOutputs
configuration option was only passed to chat models but not to completion models. This created an asymmetric API where provider-level configuration didn't apply uniformly to all model types created by the same provider instance.Bug Manifestation
When creating an OpenAI Compatible provider with
supportsStructuredOutputs: true
:Chat models correctly received the
supportsStructuredOutputs
property and used it for:json_schema
orjson_object
response format typesCompletion models completely ignored this provider setting:
supportsStructuredOutputs
property was absent from the model instanceImpact Assessment
While completion models in the current implementation don't actively use structured outputs for request formatting (they issue a blanket warning for non-text response formats), this inconsistency creates several problems:
supportsStructuredOutputs
property on completion models to understand the provider's capabilitiesRoot Cause
The issue originated in the provider factory function (
packages/openai-compatible/src/openai-compatible-provider.ts
). ThecreateChatModel
function correctly passed thesupportsStructuredOutputs
option:But the
createCompletionModel
function was missing this parameter:Additionally, the
OpenAICompatibleCompletionLanguageModel
class lacked the infrastructure to handle this property, missing both the configuration type definition and the instance property.Solution Implementation
The fix required changes to both the completion model class and the provider:
1. Enhanced Completion Model Configuration Type
Added
supportsStructuredOutputs
to theOpenAICompatibleCompletionConfig
type:2. Added Instance Property
Added the
supportsStructuredOutputs
readonly property to the completion model class:3. Constructor Initialization
Modified the constructor to initialize the property with the same default behavior as chat models:
4. Provider Configuration Passing
Updated the provider to pass the
supportsStructuredOutputs
option to completion models:Verification
The fix was validated through comprehensive testing showing that both model types now consistently receive the provider's
supportsStructuredOutputs
setting:All existing tests continue to pass, confirming the fix doesn't introduce regressions. The change maintains backward compatibility since the property defaults to
false
when not specified, matching the previous implicit behavior.No newline at end of file