From 6f300ddf9483f175b149c6490bc6ef07ee731512 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 21 Jul 2023 19:09:20 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(custom=5Fcomponent.py):=20ad?= =?UTF-8?q?d=20missing=20build=5Fconfig=20method=20to=20CustomComponent=20?= =?UTF-8?q?class=20=F0=9F=90=9B=20fix(types.py):=20update=20build=5Flangch?= =?UTF-8?q?ain=5Ftemplate=5Fcustom=5Fcomponent=20function=20to=20use=20bui?= =?UTF-8?q?ld=5Fconfig=20method=20of=20CustomComponent=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/interface/custom/custom_component.py | 3 +++ src/backend/langflow/interface/types.py | 14 ++++++++++---- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/backend/langflow/interface/custom/custom_component.py b/src/backend/langflow/interface/custom/custom_component.py index f32c82ef9..b910c14e9 100644 --- a/src/backend/langflow/interface/custom/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component.py @@ -26,6 +26,9 @@ class CustomComponent(Component, extra=Extra.allow): def custom_repr(self): return self.repr_value + def build_config(self): + return self.field_config + def _class_template_validation(self, code: str) -> bool: if not code: raise HTTPException( diff --git a/src/backend/langflow/interface/types.py b/src/backend/langflow/interface/types.py index ba645bb15..a58957e01 100644 --- a/src/backend/langflow/interface/types.py +++ b/src/backend/langflow/interface/types.py @@ -3,6 +3,7 @@ from langflow.interface.chains.base import chain_creator from langflow.interface.custom.constants import LANGCHAIN_BASE_TYPES from langflow.interface.document_loaders.base import documentloader_creator from langflow.interface.embeddings.base import embedding_creator +from langflow.interface.importing.utils import get_function_custom from langflow.interface.llms.base import llm_creator from langflow.interface.memories.base import memory_creator from langflow.interface.prompts.base import prompt_creator @@ -21,7 +22,7 @@ from langflow.template.frontend_node.tools import CustomComponentNode from langflow.interface.retrievers.base import retriever_creator from langflow.interface.custom.load_custom_component_from_path import DirectoryReader - +from langflow.utils.logger import logger import re import warnings import traceback @@ -163,10 +164,10 @@ def build_langchain_template_custom_component(custom_component: CustomComponent) function_args = custom_component.get_function_entrypoint_args return_type = custom_component.get_function_entrypoint_return_type - template_config = custom_component.build_template_config - # Rewrite diplay_name and description values if frontend_node: + template_config = custom_component.build_template_config + if "display_name" in template_config: frontend_node["display_name"] = template_config["display_name"] @@ -174,7 +175,12 @@ def build_langchain_template_custom_component(custom_component: CustomComponent) frontend_node["description"] = template_config["description"] # Rewrite field configurations - field_config = template_config.get("field_config", {}) + try: + custom_class = get_function_custom(custom_component.code) + field_config = custom_class().build_config() + except Exception as exc: + logger.error(f"Error while building custom component: {exc}") + field_config = {} if function_args is not None: # Add extra fields