From 43e24cd4a1e84dbd87abf9e37de719681eaf8695 Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Wed, 20 Nov 2024 09:19:03 -0800 Subject: [PATCH] docs, standard-tests: property tags, support tool decorator (#28234) --- .../how_to/integrations/standard_tests.ipynb | 8 ++++++++ .../standard-tests/langchain_tests/unit_tests/tools.py | 10 +++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/docs/contributing/how_to/integrations/standard_tests.ipynb b/docs/docs/contributing/how_to/integrations/standard_tests.ipynb index f98a9ef7471d5..0a275ccd638f1 100644 --- a/docs/docs/contributing/how_to/integrations/standard_tests.ipynb +++ b/docs/docs/contributing/how_to/integrations/standard_tests.ipynb @@ -116,12 +116,14 @@ " def tool_constructor(self) -> Type[ParrotMultiplyTool]:\n", " return ParrotMultiplyTool\n", "\n", + " @property\n", " def tool_constructor_params(self) -> dict:\n", " # if your tool constructor instead required initialization arguments like\n", " # `def __init__(self, some_arg: int):`, you would return those here\n", " # as a dictionary, e.g.: `return {'some_arg': 42}`\n", " return {}\n", "\n", + " @property\n", " def tool_invoke_params_example(self) -> dict:\n", " \"\"\"\n", " Returns a dictionary representing the \"args\" of an example tool call.\n", @@ -150,12 +152,14 @@ " def tool_constructor(self) -> Type[ParrotMultiplyTool]:\n", " return ParrotMultiplyTool\n", "\n", + " @property\n", " def tool_constructor_params(self) -> dict:\n", " # if your tool constructor instead required initialization arguments like\n", " # `def __init__(self, some_arg: int):`, you would return those here\n", " # as a dictionary, e.g.: `return {'some_arg': 42}`\n", " return {}\n", "\n", + " @property\n", " def tool_invoke_params_example(self) -> dict:\n", " \"\"\"\n", " Returns a dictionary representing the \"args\" of an example tool call.\n", @@ -322,12 +326,14 @@ " def tool_constructor(self) -> Type[ParrotMultiplyTool]:\n", " return ParrotMultiplyTool\n", "\n", + " @property\n", " def tool_constructor_params(self) -> dict:\n", " # if your tool constructor instead required initialization arguments like\n", " # `def __init__(self, some_arg: int):`, you would return those here\n", " # as a dictionary, e.g.: `return {'some_arg': 42}`\n", " return {}\n", "\n", + " @property\n", " def tool_invoke_params_example(self) -> dict:\n", " \"\"\"\n", " Returns a dictionary representing the \"args\" of an example tool call.\n", @@ -356,12 +362,14 @@ " def tool_constructor(self) -> Type[ParrotMultiplyTool]:\n", " return ParrotMultiplyTool\n", "\n", + " @property\n", " def tool_constructor_params(self) -> dict:\n", " # if your tool constructor instead required initialization arguments like\n", " # `def __init__(self, some_arg: int):`, you would return those here\n", " # as a dictionary, e.g.: `return {'some_arg': 42}`\n", " return {}\n", "\n", + " @property\n", " def tool_invoke_params_example(self) -> dict:\n", " \"\"\"\n", " Returns a dictionary representing the \"args\" of an example tool call.\n", diff --git a/libs/standard-tests/langchain_tests/unit_tests/tools.py b/libs/standard-tests/langchain_tests/unit_tests/tools.py index b92cb4f5263a4..46d0de7e8eaa5 100644 --- a/libs/standard-tests/langchain_tests/unit_tests/tools.py +++ b/libs/standard-tests/langchain_tests/unit_tests/tools.py @@ -13,7 +13,7 @@ class ToolsTests(BaseStandardTests): @property @abstractmethod - def tool_constructor(self) -> Union[Type[BaseTool], Callable]: ... + def tool_constructor(self) -> Union[Type[BaseTool], Callable, BaseTool]: ... @property def tool_constructor_params(self) -> dict: @@ -31,6 +31,14 @@ def tool_invoke_params_example(self) -> dict: @pytest.fixture def tool(self) -> BaseTool: + if isinstance(self.tool_constructor, BaseTool): + if self.tool_constructor_params != {}: + msg = ( + "If tool_constructor is an instance of BaseTool, " + "tool_constructor_params must be empty" + ) + raise ValueError(msg) + return self.tool_constructor return self.tool_constructor(**self.tool_constructor_params)