Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 1 addition & 69 deletions libs/core/langchain_core/utils/function_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__
Expand Down Expand Up @@ -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 = {}

Expand Down Expand Up @@ -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,
*,
Expand Down
Loading