From 590026671a4280558703e176b9cbcdda318601f4 Mon Sep 17 00:00:00 2001 From: ccurme Date: Thu, 25 Apr 2024 14:50:39 -0400 Subject: [PATCH] core, community: deprecate tool.__call__ (#20900) Does not update docs. --- .../tools/edenai/test_audio_speech_to_text.py | 2 +- .../tools/edenai/test_audio_text_to_speech.py | 2 +- .../tools/edenai/test_image_explicitcontent.py | 2 +- .../tools/edenai/test_image_objectdetection.py | 2 +- .../tools/edenai/test_ocr_identityparser.py | 2 +- .../tools/edenai/test_ocr_invoiceparser.py | 4 +++- .../tools/edenai/test_text_moderation.py | 2 +- .../tests/integration_tests/utilities/test_arxiv.py | 2 +- .../utilities/test_duckduckdgo_search_api.py | 4 ++-- .../tests/integration_tests/utilities/test_pubmed.py | 2 +- .../tests/unit_tests/tools/eden_ai/test_tools.py | 2 +- libs/core/langchain_core/tools.py | 2 ++ libs/core/tests/unit_tests/test_tools.py | 8 ++++---- 13 files changed, 20 insertions(+), 16 deletions(-) diff --git a/libs/community/tests/integration_tests/tools/edenai/test_audio_speech_to_text.py b/libs/community/tests/integration_tests/tools/edenai/test_audio_speech_to_text.py index 6dc5b160ba6e1..000fc669cf229 100644 --- a/libs/community/tests/integration_tests/tools/edenai/test_audio_speech_to_text.py +++ b/libs/community/tests/integration_tests/tools/edenai/test_audio_speech_to_text.py @@ -15,7 +15,7 @@ def test_edenai_call() -> None: """Test simple call to edenai's speech to text endpoint.""" speech2text = EdenAiSpeechToTextTool(providers=["amazon"]) - output = speech2text( + output = speech2text.invoke( "https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3" ) diff --git a/libs/community/tests/integration_tests/tools/edenai/test_audio_text_to_speech.py b/libs/community/tests/integration_tests/tools/edenai/test_audio_text_to_speech.py index 780785e93f6b7..31c42ccf42a19 100644 --- a/libs/community/tests/integration_tests/tools/edenai/test_audio_text_to_speech.py +++ b/libs/community/tests/integration_tests/tools/edenai/test_audio_text_to_speech.py @@ -19,7 +19,7 @@ def test_edenai_call() -> None: providers=["amazon"], language="en", voice="MALE" ) - output = text2speech("hello") + output = text2speech.invoke("hello") parsed_url = urlparse(output) assert text2speech.name == "edenai_text_to_speech" diff --git a/libs/community/tests/integration_tests/tools/edenai/test_image_explicitcontent.py b/libs/community/tests/integration_tests/tools/edenai/test_image_explicitcontent.py index 8ff311d55475b..9f76ebdc9bd5c 100644 --- a/libs/community/tests/integration_tests/tools/edenai/test_image_explicitcontent.py +++ b/libs/community/tests/integration_tests/tools/edenai/test_image_explicitcontent.py @@ -15,7 +15,7 @@ def test_edenai_call() -> None: """Test simple call to edenai's image moderation endpoint.""" 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.feature == "image" diff --git a/libs/community/tests/integration_tests/tools/edenai/test_image_objectdetection.py b/libs/community/tests/integration_tests/tools/edenai/test_image_objectdetection.py index 5f23fe9476844..d68b0193042a0 100644 --- a/libs/community/tests/integration_tests/tools/edenai/test_image_objectdetection.py +++ b/libs/community/tests/integration_tests/tools/edenai/test_image_objectdetection.py @@ -15,7 +15,7 @@ def test_edenai_call() -> None: """Test simple call to edenai's object detection endpoint.""" 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.feature == "image" diff --git a/libs/community/tests/integration_tests/tools/edenai/test_ocr_identityparser.py b/libs/community/tests/integration_tests/tools/edenai/test_ocr_identityparser.py index 02f659fa64686..c0234a673fe4e 100644 --- a/libs/community/tests/integration_tests/tools/edenai/test_ocr_identityparser.py +++ b/libs/community/tests/integration_tests/tools/edenai/test_ocr_identityparser.py @@ -15,7 +15,7 @@ def test_edenai_call() -> None: """Test simple call to edenai's identity parser endpoint.""" 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" ) diff --git a/libs/community/tests/integration_tests/tools/edenai/test_ocr_invoiceparser.py b/libs/community/tests/integration_tests/tools/edenai/test_ocr_invoiceparser.py index 9bd8493d85e9b..c8a62b8e61884 100644 --- a/libs/community/tests/integration_tests/tools/edenai/test_ocr_invoiceparser.py +++ b/libs/community/tests/integration_tests/tools/edenai/test_ocr_invoiceparser.py @@ -15,7 +15,9 @@ def test_edenai_call() -> None: """Test simple call to edenai's invoice parser endpoint.""" 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.feature == "ocr" diff --git a/libs/community/tests/integration_tests/tools/edenai/test_text_moderation.py b/libs/community/tests/integration_tests/tools/edenai/test_text_moderation.py index e929db0bb7294..0a6d2e9c28197 100644 --- a/libs/community/tests/integration_tests/tools/edenai/test_text_moderation.py +++ b/libs/community/tests/integration_tests/tools/edenai/test_text_moderation.py @@ -16,7 +16,7 @@ def test_edenai_call() -> None: 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.feature == "text" diff --git a/libs/community/tests/integration_tests/utilities/test_arxiv.py b/libs/community/tests/integration_tests/utilities/test_arxiv.py index a0799c9c3d67b..c11ae32732814 100644 --- a/libs/community/tests/integration_tests/utilities/test_arxiv.py +++ b/libs/community/tests/integration_tests/utilities/test_arxiv.py @@ -151,7 +151,7 @@ def _load_arxiv_from_universal_entry(**kwargs: Any) -> BaseTool: def test_load_arxiv_from_universal_entry() -> None: arxiv_tool = _load_arxiv_from_universal_entry() - output = arxiv_tool("Caprice Stanley") + output = arxiv_tool.invoke("Caprice Stanley") assert ( "On Mixing Behavior of a Family of Random Walks" in output ), "failed to fetch a valid result" diff --git a/libs/community/tests/integration_tests/utilities/test_duckduckdgo_search_api.py b/libs/community/tests/integration_tests/utilities/test_duckduckdgo_search_api.py index d8e20b81a21be..220dc048a54e6 100644 --- a/libs/community/tests/integration_tests/utilities/test_duckduckdgo_search_api.py +++ b/libs/community/tests/integration_tests/utilities/test_duckduckdgo_search_api.py @@ -20,7 +20,7 @@ def ddg_installed() -> bool: def test_ddg_search_tool() -> None: keywords = "Bella Ciao" tool = DuckDuckGoSearchRun() - result = tool(keywords) + result = tool.invoke(keywords) print(result) # noqa: T201 assert len(result.split()) > 20 @@ -29,6 +29,6 @@ def test_ddg_search_tool() -> None: def test_ddg_search_news_tool() -> None: keywords = "Tesla" tool = DuckDuckGoSearchResults(source="news") - result = tool(keywords) + result = tool.invoke(keywords) print(result) # noqa: T201 assert len(result.split()) > 20 diff --git a/libs/community/tests/integration_tests/utilities/test_pubmed.py b/libs/community/tests/integration_tests/utilities/test_pubmed.py index e3b67f2f62856..67bd85ec89708 100644 --- a/libs/community/tests/integration_tests/utilities/test_pubmed.py +++ b/libs/community/tests/integration_tests/utilities/test_pubmed.py @@ -147,7 +147,7 @@ def test_load_pupmed_from_universal_entry() -> None: "Examining the Validity of ChatGPT in Identifying " "Relevant Nephrology Literature" ) - output = pubmed_tool(search_string) + output = pubmed_tool.invoke(search_string) test_string = ( "Examining the Validity of ChatGPT in Identifying " "Relevant Nephrology Literature: Findings and Implications" diff --git a/libs/community/tests/unit_tests/tools/eden_ai/test_tools.py b/libs/community/tests/unit_tests/tools/eden_ai/test_tools.py index 773a88102a163..3a1b4ca86af1a 100644 --- a/libs/community/tests/unit_tests/tools/eden_ai/test_tools.py +++ b/libs/community/tests/unit_tests/tools/eden_ai/test_tools.py @@ -100,6 +100,6 @@ def test_parse_response_format(mock_post: MagicMock) -> None: ] 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' diff --git a/libs/core/langchain_core/tools.py b/libs/core/langchain_core/tools.py index 644701fb95fb4..b86df57397436 100644 --- a/libs/core/langchain_core/tools.py +++ b/libs/core/langchain_core/tools.py @@ -41,6 +41,7 @@ Union, ) +from langchain_core._api import deprecated from langchain_core.callbacks import ( AsyncCallbackManager, AsyncCallbackManagerForToolRun, @@ -601,6 +602,7 @@ async def arun( ) 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) diff --git a/libs/core/tests/unit_tests/test_tools.py b/libs/core/tests/unit_tests/test_tools.py index 380c93d4951b2..9a2c37b42ec90 100644 --- a/libs/core/tests/unit_tests/test_tools.py +++ b/libs/core/tests/unit_tests/test_tools.py @@ -41,7 +41,7 @@ def search_api(query: str) -> str: 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): @@ -596,7 +596,7 @@ def search_api(query: str) -> str: 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 @@ -606,7 +606,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" @@ -624,7 +624,7 @@ async def _test_func(x: str) -> str: 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