Fix Python RePL Tool (#4137)

Filter out kwargs from inferred schema when determining if a tool is
single input.

Add a couple unit tests.

Move tool unit tests to the tools dir
This commit is contained in:
Zander Chase
2023-05-04 20:31:16 -07:00
committed by GitHub
parent cc068f1b77
commit 2f087d63af
6 changed files with 464 additions and 384 deletions

View File

@@ -146,7 +146,8 @@ class BaseTool(ABC, BaseModel, metaclass=ToolMetaclass):
@property
def is_single_input(self) -> bool:
"""Whether the tool only accepts a single input."""
return len(self.args) == 1
keys = {k for k in self.args if k != "kwargs"}
return len(keys) == 1
@property
def args(self) -> dict:

View File

@@ -36,7 +36,6 @@ class PythonREPLTool(BaseTool):
self,
query: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
**kwargs: Any,
) -> Any:
"""Use the tool."""
if self.sanitize_input:
@@ -47,7 +46,6 @@ class PythonREPLTool(BaseTool):
self,
query: str,
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
**kwargs: Any,
) -> Any:
"""Use the tool asynchronously."""
raise NotImplementedError("PythonReplTool does not support async")