Skip to content

Commit

Permalink
docs, standard-tests: property tags, support tool decorator (#28234)
Browse files Browse the repository at this point in the history
  • Loading branch information
efriis authored Nov 20, 2024
1 parent 4027da1 commit 43e24cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 9 additions & 1 deletion libs/standard-tests/langchain_tests/unit_tests/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)


Expand Down

0 comments on commit 43e24cd

Please sign in to comment.