From dc49c28afd585c7802c7139c106038b6348ee056 Mon Sep 17 00:00:00 2001 From: Mason Daugherty Date: Wed, 8 Oct 2025 23:39:08 -0400 Subject: [PATCH 1/2] chore(core): delete `function_calling.py` utils marked for removal --- .../langchain_core/utils/function_calling.py | 70 +------------------ 1 file changed, 1 insertion(+), 69 deletions(-) diff --git a/libs/core/langchain_core/utils/function_calling.py b/libs/core/langchain_core/utils/function_calling.py index 7c1f3a93cc235..3a44b5e5261cc 100644 --- a/libs/core/langchain_core/utils/function_calling.py +++ b/libs/core/langchain_core/utils/function_calling.py @@ -27,7 +27,7 @@ from typing_extensions import TypedDict, is_typeddict import langchain_core -from langchain_core._api import beta, deprecated +from langchain_core._api import beta from langchain_core.messages import AIMessage, BaseMessage, HumanMessage, ToolMessage from langchain_core.utils.json_schema import dereference_refs from langchain_core.utils.pydantic import is_basemodel_subclass @@ -168,42 +168,6 @@ def _convert_pydantic_to_openai_function( ) -convert_pydantic_to_openai_function = deprecated( - "0.1.16", - alternative="langchain_core.utils.function_calling.convert_to_openai_function()", - removal="1.0", -)(_convert_pydantic_to_openai_function) - - -@deprecated( - "0.1.16", - alternative="langchain_core.utils.function_calling.convert_to_openai_tool()", - removal="1.0", -) -def convert_pydantic_to_openai_tool( - model: type[BaseModel], - *, - name: str | None = None, - description: str | None = None, -) -> ToolDescription: - """Converts a Pydantic model to a function description for the OpenAI API. - - Args: - model: The Pydantic model to convert. - name: The name of the function. If not provided, the title of the schema will be - used. - description: The description of the function. If not provided, the description - of the schema will be used. - - Returns: - The tool description. - """ - function = _convert_pydantic_to_openai_function( - model, name=name, description=description - ) - return {"type": "function", "function": function} - - def _get_python_function_name(function: Callable) -> str: """Get the name of a Python function.""" return function.__name__ @@ -240,13 +204,6 @@ def _convert_python_function_to_openai_function( ) -convert_python_function_to_openai_function = deprecated( - "0.1.16", - alternative="langchain_core.utils.function_calling.convert_to_openai_function()", - removal="1.0", -)(_convert_python_function_to_openai_function) - - def _convert_typed_dict_to_openai_function(typed_dict: type) -> FunctionDescription: visited: dict = {} @@ -368,31 +325,6 @@ def _format_tool_to_openai_function(tool: BaseTool) -> FunctionDescription: } -format_tool_to_openai_function = deprecated( - "0.1.16", - alternative="langchain_core.utils.function_calling.convert_to_openai_function()", - removal="1.0", -)(_format_tool_to_openai_function) - - -@deprecated( - "0.1.16", - alternative="langchain_core.utils.function_calling.convert_to_openai_tool()", - removal="1.0", -) -def format_tool_to_openai_tool(tool: BaseTool) -> ToolDescription: - """Format tool into the OpenAI function API. - - Args: - tool: The tool to format. - - Returns: - The tool description. - """ - function = _format_tool_to_openai_function(tool) - return {"type": "function", "function": function} - - def convert_to_openai_function( function: dict[str, Any] | type | Callable | BaseTool, *, From 0a79ab0b6db518f712df056a1e3d5e3287e16121 Mon Sep 17 00:00:00 2001 From: ccurme Date: Tue, 14 Oct 2025 16:00:10 -0400 Subject: [PATCH 2/2] chore(langchain): update imports for deprecated functions (#33486) --- .../langchain_classic/chains/openai_tools/extraction.py | 4 +++- .../langchain_classic/tools/convert_to_openai.py | 4 +++- libs/langchain/langchain_classic/tools/render.py | 6 ++++-- .../langchain_classic/utils/openai_functions.py | 9 +++++---- .../tests/unit_tests/utils/test_openai_functions.py | 6 +++--- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/libs/langchain/langchain_classic/chains/openai_tools/extraction.py b/libs/langchain/langchain_classic/chains/openai_tools/extraction.py index 276a0548e4dcb..716d94cbdeb60 100644 --- a/libs/langchain/langchain_classic/chains/openai_tools/extraction.py +++ b/libs/langchain/langchain_classic/chains/openai_tools/extraction.py @@ -3,7 +3,9 @@ from langchain_core.output_parsers.openai_tools import PydanticToolsParser from langchain_core.prompts import ChatPromptTemplate from langchain_core.runnables import Runnable -from langchain_core.utils.function_calling import convert_pydantic_to_openai_function +from langchain_core.utils.function_calling import ( + convert_to_openai_function as convert_pydantic_to_openai_function, +) from pydantic import BaseModel _EXTRACTION_TEMPLATE = """Extract and save the relevant entities mentioned \ diff --git a/libs/langchain/langchain_classic/tools/convert_to_openai.py b/libs/langchain/langchain_classic/tools/convert_to_openai.py index d9f639a382fe9..1e185e3d248dc 100644 --- a/libs/langchain/langchain_classic/tools/convert_to_openai.py +++ b/libs/langchain/langchain_classic/tools/convert_to_openai.py @@ -1,4 +1,6 @@ -from langchain_core.utils.function_calling import format_tool_to_openai_function +from langchain_core.utils.function_calling import ( + convert_to_openai_function as format_tool_to_openai_function, +) # For backwards compatibility __all__ = ["format_tool_to_openai_function"] diff --git a/libs/langchain/langchain_classic/tools/render.py b/libs/langchain/langchain_classic/tools/render.py index cbe6e2bb0e93c..50604080499a1 100644 --- a/libs/langchain/langchain_classic/tools/render.py +++ b/libs/langchain/langchain_classic/tools/render.py @@ -11,8 +11,10 @@ render_text_description_and_args, ) from langchain_core.utils.function_calling import ( - format_tool_to_openai_function, - format_tool_to_openai_tool, + convert_to_openai_function as format_tool_to_openai_function, +) +from langchain_core.utils.function_calling import ( + convert_to_openai_tool as format_tool_to_openai_tool, ) __all__ = [ diff --git a/libs/langchain/langchain_classic/utils/openai_functions.py b/libs/langchain/langchain_classic/utils/openai_functions.py index 6e093c35d6f51..0e21c36857f94 100644 --- a/libs/langchain/langchain_classic/utils/openai_functions.py +++ b/libs/langchain/langchain_classic/utils/openai_functions.py @@ -1,8 +1,9 @@ +from langchain_core.utils.function_calling import FunctionDescription, ToolDescription from langchain_core.utils.function_calling import ( - FunctionDescription, - ToolDescription, - convert_pydantic_to_openai_function, - convert_pydantic_to_openai_tool, + convert_to_openai_function as convert_pydantic_to_openai_function, +) +from langchain_core.utils.function_calling import ( + convert_to_openai_tool as convert_pydantic_to_openai_tool, ) __all__ = [ diff --git a/libs/langchain/tests/unit_tests/utils/test_openai_functions.py b/libs/langchain/tests/unit_tests/utils/test_openai_functions.py index ffe68e64ffaaa..570cd4d351de2 100644 --- a/libs/langchain/tests/unit_tests/utils/test_openai_functions.py +++ b/libs/langchain/tests/unit_tests/utils/test_openai_functions.py @@ -1,4 +1,4 @@ -from langchain_core.utils.function_calling import convert_pydantic_to_openai_function +from langchain_core.utils.function_calling import convert_to_openai_function from pydantic import BaseModel, Field @@ -9,7 +9,7 @@ class Data(BaseModel): key: str = Field(..., description="API key") days: int = Field(default=0, description="Number of days to forecast") - actual = convert_pydantic_to_openai_function(Data) + actual = convert_to_openai_function(Data) expected = { "name": "Data", "description": "The data to return.", @@ -41,7 +41,7 @@ class Model(BaseModel): data: Data - actual = convert_pydantic_to_openai_function(Model) + actual = convert_to_openai_function(Model) expected = { "name": "Model", "description": "The model to return.",