[azure-ai-inference] Support dict response_format for LangChain compatibility#46079
Open
hashwnath wants to merge 1 commit intoAzure:mainfrom
Open
[azure-ai-inference] Support dict response_format for LangChain compatibility#46079hashwnath wants to merge 1 commit intoAzure:mainfrom
hashwnath wants to merge 1 commit intoAzure:mainfrom
Conversation
…sponse_format
Fix _get_internal_response_format to handle OpenAI-style dict
response_format (e.g. {"type": "json_schema", "json_schema": {...}}).
This enables LangChain's AzureAIChatCompletionsModel and other
frameworks that pass response_format as a dict instead of a string
or JsonSchemaFormat object.
Supports dict types: "text", "json_object", and "json_schema".
Raises ValueError for unsupported dict types.
Fixes Azure#44201
|
Thank you for your contribution @hashwnath! We will review the pull request and get back to you soon. |
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.
Summary
Fixes #44201
_get_internal_response_format()currently only acceptsstr("text","json_object") andJsonSchemaFormatobjects. When LangChain'sAzureAIChatCompletionsModel(and other OpenAI-compatible frameworks) passresponse_formatas an OpenAI-style dict like{"type": "json_schema", "json_schema": {...}}, the function raisesValueError: Unsupported response_format.This PR adds a
dicthandling branch that converts:{"type": "text"}→ChatCompletionsResponseFormatText{"type": "json_object"}→ChatCompletionsResponseFormatJsonObject{"type": "json_schema", "json_schema": {"name": ..., "schema": ..., "strict": ..., "description": ...}}→ChatCompletionsResponseFormatJsonSchemaUnsupported dict types raise
ValueErrorwith a descriptive message.The async path (
aio/_patch.py) imports_get_internal_response_formatfrom the sync module, so this single fix covers both sync and async clients.Test Plan
tests/test_response_format_conversion.py: