Skip to content

Commit e6633a7

Browse files
authored
langchain-core: Add image_generation tool to list of known openai tools (#31396)
Add image generation tool to the list of well known tools. This is needed for changes in the ChatOpenAI client. TODO: Some of this logic needs to be moved from core directly into the client as changes in core should not be required to add a new tool to the openai chat client.
1 parent d9631ed commit e6633a7

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

libs/core/langchain_core/utils/function_calling.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,20 @@ def convert_to_openai_function(
506506
return oai_function
507507

508508

509+
# List of well known tools supported by OpenAI's chat models or responses API.
510+
# These tools are not expected to be supported by other chat model providers
511+
# that conform to the OpenAI function-calling API.
512+
_WellKnownOpenAITools = (
513+
"function",
514+
"file_search",
515+
"computer_use_preview",
516+
"code_interpreter",
517+
"mcp",
518+
"image_generation",
519+
"web_search_preview",
520+
)
521+
522+
509523
def convert_to_openai_tool(
510524
tool: Union[dict[str, Any], type[BaseModel], Callable, BaseTool],
511525
*,
@@ -558,15 +572,13 @@ def convert_to_openai_tool(
558572
.. versionchanged:: 0.3.61
559573
560574
Added support for OpenAI's built-in code interpreter and remote MCP tools.
575+
576+
.. versionchanged:: 0.3.63
577+
578+
Added support for OpenAI's image generation built-in tool.
561579
"""
562580
if isinstance(tool, dict):
563-
if tool.get("type") in (
564-
"function",
565-
"file_search",
566-
"computer_use_preview",
567-
"code_interpreter",
568-
"mcp",
569-
):
581+
if tool.get("type") in _WellKnownOpenAITools:
570582
return tool
571583
# As of 03.12.25 can be "web_search_preview" or "web_search_preview_2025_03_11"
572584
if (tool.get("type") or "").startswith("web_search_preview"):

0 commit comments

Comments
 (0)