openai[patch]: support Responses API (#30231)

Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
ccurme
2025-03-12 12:25:46 -04:00
committed by GitHub
parent 49bdd3b6fe
commit cd1ea8e94d
12 changed files with 1933 additions and 74 deletions

View File

@@ -443,6 +443,11 @@ def add_ai_message_chunks(
else:
usage_metadata = None
id = None
for id_ in [left.id] + [o.id for o in others]:
if id_:
id = id_
break
return left.__class__(
example=left.example,
content=content,
@@ -450,7 +455,7 @@ def add_ai_message_chunks(
tool_call_chunks=tool_call_chunks,
response_metadata=response_metadata,
usage_metadata=usage_metadata,
id=left.id,
id=id,
)

View File

@@ -531,9 +531,19 @@ def convert_to_openai_tool(
'description' and 'parameters' keys are now optional. Only 'name' is
required and guaranteed to be part of the output.
.. versionchanged:: 0.3.44
Return OpenAI Responses API-style tools unchanged. This includes
any dict with "type" in "file_search", "function", "computer_use_preview",
"web_search_preview".
"""
if isinstance(tool, dict) and tool.get("type") == "function" and "function" in tool:
return tool
if isinstance(tool, dict):
if tool.get("type") in ("function", "file_search", "computer_use_preview"):
return tool
# As of 03.12.25 can be "web_search_preview" or "web_search_preview_2025_03_11"
if (tool.get("type") or "").startswith("web_search_preview"):
return tool
oai_function = convert_to_openai_function(tool, strict=strict)
return {"type": "function", "function": oai_function}

View File

@@ -17,7 +17,7 @@ dependencies = [
"pydantic<3.0.0,>=2.7.4; python_full_version >= \"3.12.4\"",
]
name = "langchain-core"
version = "0.3.44"
version = "0.3.45-rc.1"
description = "Building applications with LLMs through composability"
readme = "README.md"