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
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 20 additions and 16 deletions

View File

@ -15,7 +15,7 @@ def test_edenai_call() -> None:
"""Test simple call to edenai's speech to text endpoint.""" """Test simple call to edenai's speech to text endpoint."""
speech2text = EdenAiSpeechToTextTool(providers=["amazon"]) speech2text = EdenAiSpeechToTextTool(providers=["amazon"])
output = speech2text( output = speech2text.invoke(
"https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3" "https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3"
) )

View File

@ -19,7 +19,7 @@ def test_edenai_call() -> None:
providers=["amazon"], language="en", voice="MALE" providers=["amazon"], language="en", voice="MALE"
) )
output = text2speech("hello") output = text2speech.invoke("hello")
parsed_url = urlparse(output) parsed_url = urlparse(output)
assert text2speech.name == "edenai_text_to_speech" assert text2speech.name == "edenai_text_to_speech"

View File

@ -15,7 +15,7 @@ def test_edenai_call() -> None:
"""Test simple call to edenai's image moderation endpoint.""" """Test simple call to edenai's image moderation endpoint."""
image_moderation = EdenAiExplicitImageTool(providers=["amazon"]) image_moderation = EdenAiExplicitImageTool(providers=["amazon"])
output = image_moderation("https://static.javatpoint.com/images/objects.jpg") output = image_moderation.invoke("https://static.javatpoint.com/images/objects.jpg")
assert image_moderation.name == "edenai_image_explicit_content_detection" assert image_moderation.name == "edenai_image_explicit_content_detection"
assert image_moderation.feature == "image" assert image_moderation.feature == "image"

View File

@ -15,7 +15,7 @@ def test_edenai_call() -> None:
"""Test simple call to edenai's object detection endpoint.""" """Test simple call to edenai's object detection endpoint."""
object_detection = EdenAiObjectDetectionTool(providers=["google"]) object_detection = EdenAiObjectDetectionTool(providers=["google"])
output = object_detection("https://static.javatpoint.com/images/objects.jpg") output = object_detection.invoke("https://static.javatpoint.com/images/objects.jpg")
assert object_detection.name == "edenai_object_detection" assert object_detection.name == "edenai_object_detection"
assert object_detection.feature == "image" assert object_detection.feature == "image"

View File

@ -15,7 +15,7 @@ def test_edenai_call() -> None:
"""Test simple call to edenai's identity parser endpoint.""" """Test simple call to edenai's identity parser endpoint."""
id_parser = EdenAiParsingIDTool(providers=["amazon"], language="en") id_parser = EdenAiParsingIDTool(providers=["amazon"], language="en")
output = id_parser( output = id_parser.invoke(
"https://www.citizencard.com/images/citizencard-uk-id-card-2023.jpg" "https://www.citizencard.com/images/citizencard-uk-id-card-2023.jpg"
) )

View File

@ -15,7 +15,9 @@ def test_edenai_call() -> None:
"""Test simple call to edenai's invoice parser endpoint.""" """Test simple call to edenai's invoice parser endpoint."""
invoice_parser = EdenAiParsingInvoiceTool(providers=["amazon"], language="en") invoice_parser = EdenAiParsingInvoiceTool(providers=["amazon"], language="en")
output = invoice_parser("https://app.edenai.run/assets/img/data_1.72e3bdcc.png") output = invoice_parser.invoke(
"https://app.edenai.run/assets/img/data_1.72e3bdcc.png"
)
assert invoice_parser.name == "edenai_invoice_parsing" assert invoice_parser.name == "edenai_invoice_parsing"
assert invoice_parser.feature == "ocr" assert invoice_parser.feature == "ocr"

View File

@ -16,7 +16,7 @@ def test_edenai_call() -> None:
text_moderation = EdenAiTextModerationTool(providers=["openai"], language="en") text_moderation = EdenAiTextModerationTool(providers=["openai"], language="en")
output = text_moderation("i hate you") output = text_moderation.invoke("i hate you")
assert text_moderation.name == "edenai_explicit_content_detection_text" assert text_moderation.name == "edenai_explicit_content_detection_text"
assert text_moderation.feature == "text" assert text_moderation.feature == "text"

View File

@ -151,7 +151,7 @@ def _load_arxiv_from_universal_entry(**kwargs: Any) -> BaseTool:
def test_load_arxiv_from_universal_entry() -> None: def test_load_arxiv_from_universal_entry() -> None:
arxiv_tool = _load_arxiv_from_universal_entry() arxiv_tool = _load_arxiv_from_universal_entry()
output = arxiv_tool("Caprice Stanley") output = arxiv_tool.invoke("Caprice Stanley")
assert ( assert (
"On Mixing Behavior of a Family of Random Walks" in output "On Mixing Behavior of a Family of Random Walks" in output
), "failed to fetch a valid result" ), "failed to fetch a valid result"

View File

@ -20,7 +20,7 @@ def ddg_installed() -> bool:
def test_ddg_search_tool() -> None: def test_ddg_search_tool() -> None:
keywords = "Bella Ciao" keywords = "Bella Ciao"
tool = DuckDuckGoSearchRun() tool = DuckDuckGoSearchRun()
result = tool(keywords) result = tool.invoke(keywords)
print(result) # noqa: T201 print(result) # noqa: T201
assert len(result.split()) > 20 assert len(result.split()) > 20
@ -29,6 +29,6 @@ def test_ddg_search_tool() -> None:
def test_ddg_search_news_tool() -> None: def test_ddg_search_news_tool() -> None:
keywords = "Tesla" keywords = "Tesla"
tool = DuckDuckGoSearchResults(source="news") tool = DuckDuckGoSearchResults(source="news")
result = tool(keywords) result = tool.invoke(keywords)
print(result) # noqa: T201 print(result) # noqa: T201
assert len(result.split()) > 20 assert len(result.split()) > 20

View File

@ -147,7 +147,7 @@ def test_load_pupmed_from_universal_entry() -> None:
"Examining the Validity of ChatGPT in Identifying " "Examining the Validity of ChatGPT in Identifying "
"Relevant Nephrology Literature" "Relevant Nephrology Literature"
) )
output = pubmed_tool(search_string) output = pubmed_tool.invoke(search_string)
test_string = ( test_string = (
"Examining the Validity of ChatGPT in Identifying " "Examining the Validity of ChatGPT in Identifying "
"Relevant Nephrology Literature: Findings and Implications" "Relevant Nephrology Literature: Findings and Implications"

View File

@ -100,6 +100,6 @@ def test_parse_response_format(mock_post: MagicMock) -> None:
] ]
mock_post.return_value = mock_response mock_post.return_value = mock_response
result = tool("some query") result = tool.invoke("some query")
assert result == 'nsfw_likelihood: 5\n"offensive": 4\n"hate_speech": 5' assert result == 'nsfw_likelihood: 5\n"offensive": 4\n"hate_speech": 5'

View File

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

View File

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