refactor(loading.py): add support for instantiating tool nodes

refactor(tools/base.py): comment out unused code for ToolCreator
feat(nodes.py): add 'return_direct' field to ToolNode template and set base class to 'Tool'
This commit is contained in:
Gabriel Almeida 2023-04-19 00:46:57 -03:00
commit cd241c22c7
3 changed files with 18 additions and 8 deletions

View file

@ -56,6 +56,8 @@ def instantiate_class(node_type: str, base_type: str, params: Dict) -> Any:
if isinstance(function_string, str):
return validate.eval_function(function_string)
raise ValueError("Function should be a string")
elif node_type.lower() == "tool":
return class_object(**params)
elif base_type == "toolkits":
loaded_toolkit = class_object(**params)
# Check if node_type has a loader

View file

@ -106,8 +106,8 @@ class ToolCreator(LangChainTypeCreator):
n_dict = {val[0]: val[1] for val in _EXTRA_OPTIONAL_TOOLS.values()} # type: ignore
extra_keys = n_dict[all_tools[tool_type]["fcn"]]
params = extra_keys
elif tool_type == "Tool":
params = ["name", "description", "func"]
# elif tool_type == "Tool":
# params = ["name", "description", "func"]
elif tool_type in CUSTOM_TOOLS:
# Get custom tool params
params = all_tools[name]["params"] # type: ignore

View file

@ -104,7 +104,7 @@ class PythonFunctionNode(FrontendNode):
class ToolNode(FrontendNode):
name: str = "Tool"
template: Template = Template(
type_name="tool",
type_name="Tool",
fields=[
TemplateField(
field_type="str",
@ -127,19 +127,27 @@ class ToolNode(FrontendNode):
name="description",
),
TemplateField(
field_type="str",
name="func",
field_type="function",
required=True,
is_list=False,
show=True,
multiline=True,
),
TemplateField(
field_type="bool",
required=True,
placeholder="",
is_list=False,
show=True,
multiline=True,
value="",
name="func",
multiline=False,
value=False,
name="return_direct",
),
],
)
description: str = "Tool to be used in the flow."
base_classes: list[str] = ["BaseTool"]
base_classes: list[str] = ["Tool"]
def to_dict(self):
return super().to_dict()