fix(langchain, openai): backward compat for response_format (#33945)

This commit is contained in:
ccurme
2025-11-13 11:11:35 -05:00
committed by GitHub
parent 74385e0ebd
commit 3d415441e8
2 changed files with 10 additions and 3 deletions

View File

@@ -1844,6 +1844,14 @@ class BaseChatOpenAI(BaseChatModel):
kwargs["tool_choice"] = tool_choice
if response_format:
if (
isinstance(response_format, dict)
and response_format.get("type") == "json_schema"
and "schema" in response_format.get("json_schema", {})
):
# compat with langchain.agents.create_agent response_format, which is
# an approximation of OpenAI format
response_format = cast(dict, response_format["json_schema"]["schema"])
kwargs["response_format"] = _convert_to_openai_response_format(
response_format
)