From e38cf0dd6ced6d0512f8b6a9014d3d14d2d70a10 Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Mon, 18 Mar 2024 23:40:25 +0100 Subject: [PATCH] Changed component.py to fix bug --- .../custom/custom_component/component.py | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/backend/langflow/interface/custom/custom_component/component.py b/src/backend/langflow/interface/custom/custom_component/component.py index ce40b0f74..594ec982f 100644 --- a/src/backend/langflow/interface/custom/custom_component/component.py +++ b/src/backend/langflow/interface/custom/custom_component/component.py @@ -1,3 +1,4 @@ +import ast import operator import warnings from typing import Any, ClassVar, Optional @@ -5,9 +6,7 @@ from typing import Any, ClassVar, Optional from cachetools import TTLCache, cachedmethod from fastapi import HTTPException -from langflow.interface.custom.attributes import ATTR_FUNC_MAPPING from langflow.interface.custom.code_parser import CodeParser -from langflow.interface.custom.eval import eval_custom_component_code from langflow.utils import validate @@ -39,8 +38,7 @@ class Component: def __setattr__(self, key, value): if key == "_user_id" and hasattr(self, "_user_id"): warnings.warn("user_id is immutable and cannot be changed.") - else: - super().__setattr__(key, value) + super().__setattr__(key, value) @cachedmethod(cache=operator.attrgetter("cache")) def get_code_tree(self, code: str): @@ -65,19 +63,24 @@ class Component: return validate.create_function(self.code, self._function_entrypoint_name) - def build_template_config(self) -> dict: - if not self.code: - return {} - - cc_class = eval_custom_component_code(self.code) - component_instance = cc_class() + def build_template_config(self, attributes) -> dict: template_config = {} - for attribute, func in ATTR_FUNC_MAPPING.items(): - if hasattr(component_instance, attribute): - value = getattr(component_instance, attribute) - if value is not None: - template_config[attribute] = func(value=value) + for item in attributes: + item_name = item.get("name") + + if item_value := item.get("value"): + if "display_name" in item_name: + template_config["display_name"] = ast.literal_eval(item_value) + + elif "description" in item_name: + template_config["description"] = ast.literal_eval(item_value) + + elif "beta" in item_name: + template_config["beta"] = ast.literal_eval(item_value) + + elif "documentation" in item_name: + template_config["documentation"] = ast.literal_eval(item_value) return template_config