fix(openai): add extra_body field to config models so it survives load_component#7622
Open
octo-patch wants to merge 1 commit intomicrosoft:mainfrom
Open
fix(openai): add extra_body field to config models so it survives load_component#7622octo-patch wants to merge 1 commit intomicrosoft:mainfrom
octo-patch wants to merge 1 commit intomicrosoft:mainfrom
Conversation
…d_component (fixes microsoft#7418) The CreateArguments TypedDict and CreateArgumentsConfigModel Pydantic model both lacked an extra_body field. When loading an OpenAI model client from JSON via load_component(), Pydantic silently dropped any extra_body value because the field was unknown to the schema. The fix adds extra_body: Optional[Dict[str, Any]] to both the TypedDict and the Pydantic config model, keeping them in sync with the existing create_kwargs set that already included extra_body. Adds a test that covers the constructor, load_component round-trip, and dump/load cycle for both OpenAI and Azure OpenAI clients.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #7418
Problem
extra_bodywas silently dropped when loading anOpenAIChatCompletionClient(or Azure variant) from JSON viaload_component(). The root cause was thatCreateArgumentsTypedDict andCreateArgumentsConfigModelPydantic model both lacked anextra_bodyfield. Pydantic's default behaviour is to silently ignore unknown fields, so anyextra_bodyvalue specified in the JSON config was discarded during validation — it never reached_from_configor the underlying API call.Notably,
create_kwargs(used by_create_args_from_config) already included"extra_body", so the parameter worked correctly when the client was instantiated directly via Python, but not viaload_component().Solution
Add
extra_body: Optional[Dict[str, Any]]to:CreateArgumentsTypedDict — keeps the type hints complete for direct constructionCreateArgumentsConfigModelPydantic model — allows Pydantic to retain the field during deserializationNo changes were needed to
_create_args_from_configor any call sites.Testing
Added
test_extra_body_parametercovering:extra_bodylands in_create_args)load_componentround-trip for OpenAI clientload_componentround-trip for Azure OpenAI clientdump_component/load_componentcycle