🐛 fix(interface/loading.py): fix custom_node instantiation to handle classes without initialize method ✨ feat(template/frontend_node/prompts.py): change type_name to match class name ✨ feat(template/frontend_node/tools.py): change type_name to match class name 🔥 chore(test_agents_template.py): remove test_agents_settings and update initialize_agent test The vertex_type assignment in the Vertex class was not handling uppercase template types correctly. This has been fixed to handle both uppercase and lowercase types. The custom_node instantiation in the instantiate_class function was not handling classes without an initialize method correctly. This has been fixed to instantiate the class directly if the initialize method is not present. The type_name in the ZeroShotPromptNode and PythonFunctionToolNode classes have been changed to match the class name. The test_agents_settings test has been removed as it is no longer necessary and the initialize_agent test has been updated to match the new AgentInitializer class name.
129 lines
3.6 KiB
Python
129 lines
3.6 KiB
Python
from langflow.template.field.base import TemplateField
|
|
from langflow.template.frontend_node.base import FrontendNode
|
|
from langflow.template.template.base import Template
|
|
from langflow.utils.constants import DEFAULT_PYTHON_FUNCTION
|
|
|
|
|
|
class ToolNode(FrontendNode):
|
|
name: str = "Tool"
|
|
template: Template = Template(
|
|
type_name="Tool",
|
|
fields=[
|
|
TemplateField(
|
|
field_type="str",
|
|
required=True,
|
|
placeholder="",
|
|
is_list=False,
|
|
show=True,
|
|
multiline=True,
|
|
value="",
|
|
name="name",
|
|
advanced=False,
|
|
),
|
|
TemplateField(
|
|
field_type="str",
|
|
required=True,
|
|
placeholder="",
|
|
is_list=False,
|
|
show=True,
|
|
multiline=True,
|
|
value="",
|
|
name="description",
|
|
advanced=False,
|
|
),
|
|
TemplateField(
|
|
name="func",
|
|
field_type="function",
|
|
required=True,
|
|
is_list=False,
|
|
show=True,
|
|
multiline=True,
|
|
advanced=False,
|
|
),
|
|
TemplateField(
|
|
field_type="bool",
|
|
required=True,
|
|
placeholder="",
|
|
is_list=False,
|
|
show=True,
|
|
multiline=False,
|
|
value=False,
|
|
name="return_direct",
|
|
),
|
|
],
|
|
)
|
|
description: str = "Tool to be used in the flow."
|
|
base_classes: list[str] = ["Tool"]
|
|
|
|
def to_dict(self):
|
|
return super().to_dict()
|
|
|
|
|
|
class PythonFunctionToolNode(FrontendNode):
|
|
name: str = "PythonFunctionTool"
|
|
template: Template = Template(
|
|
type_name="PythonFunctionTool",
|
|
fields=[
|
|
TemplateField(
|
|
field_type="str",
|
|
required=True,
|
|
placeholder="",
|
|
is_list=False,
|
|
show=True,
|
|
multiline=False,
|
|
value="",
|
|
name="name",
|
|
advanced=False,
|
|
),
|
|
TemplateField(
|
|
field_type="str",
|
|
required=True,
|
|
placeholder="",
|
|
is_list=False,
|
|
show=True,
|
|
multiline=False,
|
|
value="",
|
|
name="description",
|
|
advanced=False,
|
|
),
|
|
TemplateField(
|
|
field_type="code",
|
|
required=True,
|
|
placeholder="",
|
|
is_list=False,
|
|
show=True,
|
|
value=DEFAULT_PYTHON_FUNCTION,
|
|
name="code",
|
|
advanced=False,
|
|
),
|
|
],
|
|
)
|
|
description: str = "Python function to be executed."
|
|
base_classes: list[str] = ["Tool"]
|
|
|
|
def to_dict(self):
|
|
return super().to_dict()
|
|
|
|
|
|
class PythonFunctionNode(FrontendNode):
|
|
name: str = "PythonFunction"
|
|
template: Template = Template(
|
|
type_name="PythonFunction",
|
|
fields=[
|
|
TemplateField(
|
|
field_type="code",
|
|
required=True,
|
|
placeholder="",
|
|
is_list=False,
|
|
show=True,
|
|
value=DEFAULT_PYTHON_FUNCTION,
|
|
name="code",
|
|
advanced=False,
|
|
)
|
|
],
|
|
)
|
|
description: str = "Python function to be executed."
|
|
base_classes: list[str] = ["function"]
|
|
|
|
def to_dict(self):
|
|
return super().to_dict()
|