feat(custom_components.py): add CustomComponentFrontendNode class to create a custom component

The CustomComponentFrontendNode class is added to the custom_components.py file. This class represents a custom component in the frontend of the application. It has properties such as name, display_name, template, description, and base_classes. The template property defines the structure of the custom component, including a code field with default value. The to_dict() method is also implemented to convert the class instance to a dictionary. This allows the custom component to be serialized and used in other parts of the application.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-07-06 23:57:57 -03:00
commit 790d8b5669

View file

@ -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()