From 74e263811bf23aef5af7f8add8626e438964abda Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 25 Jul 2023 17:22:02 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20refactor(types.py):=20import=20C?= =?UTF-8?q?ustomComponentFrontendNode=20from=20custom=5Fcomponents=20modul?= =?UTF-8?q?e=20to=20improve=20code=20organization=20and=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🔨 refactor(types.py): change usage of CustomComponentNode to CustomComponentFrontendNode to align with updated module structure 🔨 refactor(frontend_node/base.py): add beta flag to FrontendNode class to indicate if a node is in beta stage 🔨 refactor(custom_components.py): add beta flag to CustomComponentFrontendNode class to indicate it is in beta stage 🔨 refactor(tools.py): remove unused import of DEFAULT_CUSTOM_COMPONENT_CODE 🔨 refactor(tools.py): remove CustomComponentNode class as it is no longer used --- src/backend/langflow/interface/types.py | 8 ++++-- .../langflow/template/frontend_node/base.py | 1 + .../frontend_node/custom_components.py | 1 + .../langflow/template/frontend_node/tools.py | 26 ------------------- 4 files changed, 8 insertions(+), 28 deletions(-) diff --git a/src/backend/langflow/interface/types.py b/src/backend/langflow/interface/types.py index eaaa47f2b..c81be082b 100644 --- a/src/backend/langflow/interface/types.py +++ b/src/backend/langflow/interface/types.py @@ -18,7 +18,9 @@ from langflow.interface.custom.base import custom_component_creator from langflow.interface.custom.custom_component import CustomComponent from langflow.template.field.base import TemplateField -from langflow.template.frontend_node.tools import CustomComponentNode +from langflow.template.frontend_node.custom_components import ( + CustomComponentFrontendNode, +) from langflow.interface.retrievers.base import retriever_creator from langflow.interface.custom.directory_reader import DirectoryReader @@ -160,7 +162,9 @@ def extract_type_from_optional(field_type): def build_langchain_template_custom_component(custom_component: CustomComponent): # Build base "CustomComponent" template - frontend_node = CustomComponentNode().to_dict().get(type(custom_component).__name__) + frontend_node = ( + CustomComponentFrontendNode().to_dict().get(type(custom_component).__name__) + ) function_args = custom_component.get_function_entrypoint_args return_type = custom_component.get_function_entrypoint_return_type diff --git a/src/backend/langflow/template/frontend_node/base.py b/src/backend/langflow/template/frontend_node/base.py index d6d9f911a..c78b6b913 100644 --- a/src/backend/langflow/template/frontend_node/base.py +++ b/src/backend/langflow/template/frontend_node/base.py @@ -52,6 +52,7 @@ class FrontendNode(BaseModel): custom_fields: defaultdict = defaultdict(list) output_types: List[str] = [] field_formatters: FieldFormatters = Field(default_factory=FieldFormatters) + beta: bool = False # field formatters is an instance attribute but it is not used in the class # so we need to create a method to get it diff --git a/src/backend/langflow/template/frontend_node/custom_components.py b/src/backend/langflow/template/frontend_node/custom_components.py index 8a3474d24..4f36a1c9f 100644 --- a/src/backend/langflow/template/frontend_node/custom_components.py +++ b/src/backend/langflow/template/frontend_node/custom_components.py @@ -7,6 +7,7 @@ from langflow.interface.custom.constants import DEFAULT_CUSTOM_COMPONENT_CODE class CustomComponentFrontendNode(FrontendNode): name: str = "CustomComponent" display_name: str = "Custom Component" + beta: bool = True template: Template = Template( type_name="CustomComponent", fields=[ diff --git a/src/backend/langflow/template/frontend_node/tools.py b/src/backend/langflow/template/frontend_node/tools.py index d23033b35..579b32da3 100644 --- a/src/backend/langflow/template/frontend_node/tools.py +++ b/src/backend/langflow/template/frontend_node/tools.py @@ -1,4 +1,3 @@ -from langflow.interface.custom.constants import DEFAULT_CUSTOM_COMPONENT_CODE from langflow.template.field.base import TemplateField from langflow.template.frontend_node.base import FrontendNode from langflow.template.template.base import Template @@ -140,28 +139,3 @@ class PythonFunctionNode(FrontendNode): def to_dict(self): return super().to_dict() - - -class CustomComponentNode(FrontendNode): - name: str = "CustomComponent" - 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 = "Python Class to be executed." - base_classes: list[str] = [] - - def to_dict(self): - return super().to_dict()