From c5bf15a2c487dc3146ceae17322803df95074682 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 20 Jul 2023 15:09:51 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20fix(custom=5Fcomponent.py):=20fi?= =?UTF-8?q?x=20import=20statements=20and=20refactor=20load=5Fflow=20method?= =?UTF-8?q?=20to=20use=20UUID=20and=20improve=20code=20readability=20?= =?UTF-8?q?=F0=9F=94=80=20merge(custom=5Fcomponent.py):=20merge=20changes?= =?UTF-8?q?=20from=20langflow.processing.process=20module=20to=20load=5Ffl?= =?UTF-8?q?ow=20method=20to=20improve=20performance=20and=20data=20retriev?= =?UTF-8?q?al?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../langflow/interface/custom/custom_component.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/backend/langflow/interface/custom/custom_component.py b/src/backend/langflow/interface/custom/custom_component.py index 0501d5570..2b0f1f342 100644 --- a/src/backend/langflow/interface/custom/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component.py @@ -5,7 +5,9 @@ from langflow.interface.custom.component import Component from langflow.utils import validate -from langflow.api.v1.endpoints import process_flow +from uuid import UUID +from langflow.database.base import get_session +from langflow.database.models.flow import Flow class CustomComponent(Component): @@ -128,10 +130,12 @@ class CustomComponent(Component): def get_function(self): return validate.create_function(self.code, self.function_entrypoint_name) - def load_flow( - self, flow_id: str, inputs: Optional[dict] = None, tweaks: Optional[dict] = None - ): - return process_flow(flow_id, inputs, tweaks) + def load_flow(self, flow_id: UUID = None): + from langflow.processing.process import build_sorted_vertices_with_caching + + session = next(get_session()) + data_graph = flow.data if (flow := session.get(Flow, flow_id)) else None + return build_sorted_vertices_with_caching(data_graph) def build(self): raise NotImplementedError