chore(core): delete function_calling.py utils marked for removal (#33376)

This commit is contained in:
Mason Daugherty
2025-10-14 16:13:19 -04:00
committed by GitHub
parent edae976b81
commit 68ceeb64f6
6 changed files with 19 additions and 80 deletions

View File

@@ -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,
*,

View File

@@ -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 \

View File

@@ -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"]

View File

@@ -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__ = [

View File

@@ -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__ = [

View File

@@ -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.",