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:
parent
a0da9c6111
commit
cd241c22c7
3 changed files with 18 additions and 8 deletions
|
|
@ -56,6 +56,8 @@ def instantiate_class(node_type: str, base_type: str, params: Dict) -> Any:
|
||||||
if isinstance(function_string, str):
|
if isinstance(function_string, str):
|
||||||
return validate.eval_function(function_string)
|
return validate.eval_function(function_string)
|
||||||
raise ValueError("Function should be a string")
|
raise ValueError("Function should be a string")
|
||||||
|
elif node_type.lower() == "tool":
|
||||||
|
return class_object(**params)
|
||||||
elif base_type == "toolkits":
|
elif base_type == "toolkits":
|
||||||
loaded_toolkit = class_object(**params)
|
loaded_toolkit = class_object(**params)
|
||||||
# Check if node_type has a loader
|
# Check if node_type has a loader
|
||||||
|
|
|
||||||
|
|
@ -106,8 +106,8 @@ class ToolCreator(LangChainTypeCreator):
|
||||||
n_dict = {val[0]: val[1] for val in _EXTRA_OPTIONAL_TOOLS.values()} # type: ignore
|
n_dict = {val[0]: val[1] for val in _EXTRA_OPTIONAL_TOOLS.values()} # type: ignore
|
||||||
extra_keys = n_dict[all_tools[tool_type]["fcn"]]
|
extra_keys = n_dict[all_tools[tool_type]["fcn"]]
|
||||||
params = extra_keys
|
params = extra_keys
|
||||||
elif tool_type == "Tool":
|
# elif tool_type == "Tool":
|
||||||
params = ["name", "description", "func"]
|
# params = ["name", "description", "func"]
|
||||||
elif tool_type in CUSTOM_TOOLS:
|
elif tool_type in CUSTOM_TOOLS:
|
||||||
# Get custom tool params
|
# Get custom tool params
|
||||||
params = all_tools[name]["params"] # type: ignore
|
params = all_tools[name]["params"] # type: ignore
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ class PythonFunctionNode(FrontendNode):
|
||||||
class ToolNode(FrontendNode):
|
class ToolNode(FrontendNode):
|
||||||
name: str = "Tool"
|
name: str = "Tool"
|
||||||
template: Template = Template(
|
template: Template = Template(
|
||||||
type_name="tool",
|
type_name="Tool",
|
||||||
fields=[
|
fields=[
|
||||||
TemplateField(
|
TemplateField(
|
||||||
field_type="str",
|
field_type="str",
|
||||||
|
|
@ -127,19 +127,27 @@ class ToolNode(FrontendNode):
|
||||||
name="description",
|
name="description",
|
||||||
),
|
),
|
||||||
TemplateField(
|
TemplateField(
|
||||||
field_type="str",
|
name="func",
|
||||||
|
field_type="function",
|
||||||
|
required=True,
|
||||||
|
is_list=False,
|
||||||
|
show=True,
|
||||||
|
multiline=True,
|
||||||
|
),
|
||||||
|
TemplateField(
|
||||||
|
field_type="bool",
|
||||||
required=True,
|
required=True,
|
||||||
placeholder="",
|
placeholder="",
|
||||||
is_list=False,
|
is_list=False,
|
||||||
show=True,
|
show=True,
|
||||||
multiline=True,
|
multiline=False,
|
||||||
value="",
|
value=False,
|
||||||
name="func",
|
name="return_direct",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
description: str = "Tool to be used in the flow."
|
description: str = "Tool to be used in the flow."
|
||||||
base_classes: list[str] = ["BaseTool"]
|
base_classes: list[str] = ["Tool"]
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return super().to_dict()
|
return super().to_dict()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue