diff --git a/libs/core/langchain_core/utils/function_calling.py b/libs/core/langchain_core/utils/function_calling.py index 7b237828142..f2262c36895 100644 --- a/libs/core/langchain_core/utils/function_calling.py +++ b/libs/core/langchain_core/utils/function_calling.py @@ -27,7 +27,7 @@ from pydantic.v1 import create_model as create_model_v1 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, *, diff --git a/libs/langchain/langchain_classic/chains/openai_tools/extraction.py b/libs/langchain/langchain_classic/chains/openai_tools/extraction.py index 276a0548e4d..716d94cbdeb 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.language_models import BaseLanguageModel 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 d9f639a382f..1e185e3d248 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 cbe6e2bb0e9..50604080499 100644 --- a/libs/langchain/langchain_classic/tools/render.py +++ b/libs/langchain/langchain_classic/tools/render.py @@ -11,8 +11,10 @@ from langchain_core.tools import ( 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 6e093c35d6f..0e21c36857f 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 ffe68e64ffa..570cd4d351d 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 @@ def test_convert_pydantic_to_openai_function() -> None: 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 @@ def test_convert_pydantic_to_openai_function_nested() -> None: data: Data - actual = convert_pydantic_to_openai_function(Model) + actual = convert_to_openai_function(Model) expected = { "name": "Model", "description": "The model to return.",