From 790d8b56691886996e8130f27988bb3a488d8ab4 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 6 Jul 2023 23:57:57 -0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(custom=5Fcomponents.py):=20add?= =?UTF-8?q?=20CustomComponentFrontendNode=20class=20to=20create=20a=20cust?= =?UTF-8?q?om=20component=20The=20CustomComponentFrontendNode=20class=20is?= =?UTF-8?q?=20added=20to=20the=20custom=5Fcomponents.py=20file.=20This=20c?= =?UTF-8?q?lass=20represents=20a=20custom=20component=20in=20the=20fronten?= =?UTF-8?q?d=20of=20the=20application.=20It=20has=20properties=20such=20as?= =?UTF-8?q?=20name,=20display=5Fname,=20template,=20description,=20and=20b?= =?UTF-8?q?ase=5Fclasses.=20The=20template=20property=20defines=20the=20st?= =?UTF-8?q?ructure=20of=20the=20custom=20component,=20including=20a=20code?= =?UTF-8?q?=20field=20with=20default=20value.=20The=20to=5Fdict()=20method?= =?UTF-8?q?=20is=20also=20implemented=20to=20convert=20the=20class=20insta?= =?UTF-8?q?nce=20to=20a=20dictionary.=20This=20allows=20the=20custom=20com?= =?UTF-8?q?ponent=20to=20be=20serialized=20and=20used=20in=20other=20parts?= =?UTF-8?q?=20of=20the=20application.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../frontend_node/custom_components.py | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/backend/langflow/template/frontend_node/custom_components.py diff --git a/src/backend/langflow/template/frontend_node/custom_components.py b/src/backend/langflow/template/frontend_node/custom_components.py new file mode 100644 index 000000000..6d360ce96 --- /dev/null +++ b/src/backend/langflow/template/frontend_node/custom_components.py @@ -0,0 +1,30 @@ +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_CUSTOM_COMPONENT_CODE + + +class CustomComponentFrontendNode(FrontendNode): + name: str = "CustomComponent" + display_name: str = "Custom Component" + template: Template = Template( + type_name="CustomComponent", + fields=[ + TemplateField( + field_type="code", + required=True, + placeholder="", + is_list=False, + show=True, + value=DEFAULT_CUSTOM_COMPONENT_CODE, + name="code", + advanced=False, + dynamic=True, + ) + ], + ) + description: str = "Create any custom component you want!" + base_classes: list[str] = [] + + def to_dict(self): + return super().to_dict()