Run the tool.
(
self,
tool_input: Union[str, Dict] = "",
**kwargs: Any,
)
| 88 | return self.func(*args, **kwargs) |
| 89 | |
| 90 | def run( |
| 91 | self, |
| 92 | tool_input: Union[str, Dict] = "", |
| 93 | **kwargs: Any, |
| 94 | ) -> str: |
| 95 | """Run the tool.""" |
| 96 | try: |
| 97 | parsed_input = self._parse_input(tool_input) |
| 98 | except ValueError as e: |
| 99 | # return exception as tool output |
| 100 | raise ToolRunningError(message=f"Tool input args value Error: {e}") from e |
| 101 | |
| 102 | try: |
| 103 | tool_args, tool_kwargs = self._to_args_and_kwargs(parsed_input) |
| 104 | tool_output = self._run(*tool_args, **tool_kwargs) |
| 105 | except (Exception, KeyboardInterrupt) as e: |
| 106 | raise ToolRunningError( |
| 107 | message=f"Failed to run tool {self.name} due to {e}" |
| 108 | ) from e |
| 109 | |
| 110 | return tool_output |