core, community: deprecate tool.__call__ (#20900)

Does not update docs.
This commit is contained in:
ccurme
2024-04-25 14:50:39 -04:00
committed by GitHub
parent 52896258ee
commit b8db73233c
13 changed files with 20 additions and 16 deletions

View File

@@ -29,6 +29,7 @@ from functools import partial
from inspect import signature
from typing import Any, Awaitable, Callable, Dict, List, Optional, Tuple, Type, Union
from langchain_core._api import deprecated
from langchain_core.callbacks import (
AsyncCallbackManager,
AsyncCallbackManagerForToolRun,
@@ -559,6 +560,7 @@ class ChildTool(BaseTool):
)
return observation
@deprecated("0.1.47", alternative="invoke", removal="0.3.0")
def __call__(self, tool_input: str, callbacks: Callbacks = None) -> str:
"""Make tool callable."""
return self.run(tool_input, callbacks=callbacks)

View File

@@ -39,7 +39,7 @@ def test_unnamed_decorator() -> None:
assert isinstance(search_api, BaseTool)
assert search_api.name == "search_api"
assert not search_api.return_direct
assert search_api("test") == "API result"
assert search_api.invoke("test") == "API result"
class _MockSchema(BaseModel):
@@ -562,7 +562,7 @@ def test_missing_docstring() -> None:
def test_create_tool_positional_args() -> None:
"""Test that positional arguments are allowed."""
test_tool = Tool("test_name", lambda x: x, "test_description")
assert test_tool("foo") == "foo"
assert test_tool.invoke("foo") == "foo"
assert test_tool.name == "test_name"
assert test_tool.description == "test_description"
assert test_tool.is_single_input
@@ -572,7 +572,7 @@ def test_create_tool_keyword_args() -> None:
"""Test that keyword arguments are allowed."""
test_tool = Tool(name="test_name", func=lambda x: x, description="test_description")
assert test_tool.is_single_input
assert test_tool("foo") == "foo"
assert test_tool.invoke("foo") == "foo"
assert test_tool.name == "test_name"
assert test_tool.description == "test_description"
@@ -590,7 +590,7 @@ async def test_create_async_tool() -> None:
coroutine=_test_func,
)
assert test_tool.is_single_input
assert test_tool("foo") == "foo"
assert test_tool.invoke("foo") == "foo"
assert test_tool.name == "test_name"
assert test_tool.description == "test_description"
assert test_tool.coroutine is not None