From 67b2aeae67d188f23ef4bc599b28ea57a9deaf96 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Wed, 26 Jul 2023 07:47:34 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(custom=5Fcomponent.py):=20re?= =?UTF-8?q?move=20unused=20import=20of=20UUID=20from=20langflow.interface.?= =?UTF-8?q?custom.custom=5Fcomponent.py=20=F0=9F=90=9B=20fix(custom=5Fcomp?= =?UTF-8?q?onent.py):=20handle=20case=20when=20code=20is=20None=20in=20is?= =?UTF-8?q?=5Fcheck=5Fvalid=20method=20of=20CustomComponent=20class=20?= =?UTF-8?q?=F0=9F=90=9B=20fix(custom=5Fcomponent.py):=20handle=20case=20wh?= =?UTF-8?q?en=20code=20is=20None=20in=20get=5Ffunction=5Fentrypoint=5Fargs?= =?UTF-8?q?=20property=20of=20CustomComponent=20class=20=F0=9F=90=9B=20fix?= =?UTF-8?q?(custom=5Fcomponent.py):=20handle=20case=20when=20code=20is=20N?= =?UTF-8?q?one=20in=20get=5Ffunction=5Fentrypoint=5Freturn=5Ftype=20proper?= =?UTF-8?q?ty=20of=20CustomComponent=20class=20=F0=9F=90=9B=20fix(custom?= =?UTF-8?q?=5Fcomponent.py):=20change=20flow=5Fid=20parameter=20type=20fro?= =?UTF-8?q?m=20UUID=20to=20str=20in=20load=5Fflow=20method=20of=20CustomCo?= =?UTF-8?q?mponent=20class=20=F0=9F=90=9B=20fix(util.py):=20ignore=20type?= =?UTF-8?q?=20error=20for=20multiprocess=20import=20in=20langflow.utils.ut?= =?UTF-8?q?il=20module=20=F0=9F=90=9B=20fix(util.py):=20handle=20case=20wh?= =?UTF-8?q?en=20=5Ftype=20is=20a=20type=20object=20in=20remove=5Foptional?= =?UTF-8?q?=5Fwrapper=20function=20of=20langflow.utils.util=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/interface/custom/custom_component.py | 9 ++++++--- src/backend/langflow/utils/util.py | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/backend/langflow/interface/custom/custom_component.py b/src/backend/langflow/interface/custom/custom_component.py index 1cc0ca620..2f89863ae 100644 --- a/src/backend/langflow/interface/custom/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component.py @@ -5,7 +5,6 @@ from langflow.interface.custom.component import Component from langflow.utils import validate -from uuid import UUID from langflow.database.base import session_getter from langflow.database.models.flow import Flow from pydantic import Extra @@ -44,13 +43,15 @@ class CustomComponent(Component, extra=Extra.allow): return True def is_check_valid(self) -> bool: - return self._class_template_validation(self.code) + return self._class_template_validation(self.code) if self.code else False def get_code_tree(self, code: str): return super().get_code_tree(code) @property def get_function_entrypoint_args(self) -> str: + if not self.code: + return "" tree = self.get_code_tree(self.code) component_classes = [ @@ -78,6 +79,8 @@ class CustomComponent(Component, extra=Extra.allow): @property def get_function_entrypoint_return_type(self) -> str: + if not self.code: + return "" tree = self.get_code_tree(self.code) component_classes = [ @@ -138,7 +141,7 @@ class CustomComponent(Component, extra=Extra.allow): def get_function(self): return validate.create_function(self.code, self.function_entrypoint_name) - def load_flow(self, flow_id: UUID = None): + def load_flow(self, flow_id: str): from langflow.processing.process import build_sorted_vertices_with_caching with session_getter() as session: diff --git a/src/backend/langflow/utils/util.py b/src/backend/langflow/utils/util.py index ce5f03bdf..f68c9dbe2 100644 --- a/src/backend/langflow/utils/util.py +++ b/src/backend/langflow/utils/util.py @@ -9,7 +9,7 @@ from docstring_parser import parse # type: ignore from langflow.template.frontend_node.constants import FORCE_SHOW_FIELDS from langflow.utils import constants from langflow.utils.logger import logger -from multiprocess import cpu_count +from multiprocess import cpu_count # type: ignore def build_template_from_function( @@ -301,13 +301,15 @@ def get_type(value: Any) -> Union[str, type]: return _type if isinstance(_type, str) else _type.__name__ -def remove_optional_wrapper(_type: str) -> str: +def remove_optional_wrapper(_type: Union[str, type]) -> str: """ Removes the 'Optional' wrapper from the type string. Returns: The type string with the 'Optional' wrapper removed. """ + if isinstance(_type, type): + _type = str(_type) if "Optional" in _type: _type = _type.replace("Optional[", "")[:-1]