From 46520e84a32c940b6b3631f7d3fd69022a071e5c Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 4 Mar 2024 10:26:02 -0300 Subject: [PATCH] Add flow_records attribute and update build method in RunFlowComponent --- .../langflow/components/utilities/RunFlow.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/backend/langflow/components/utilities/RunFlow.py b/src/backend/langflow/components/utilities/RunFlow.py index 16a681dec..3255fc875 100644 --- a/src/backend/langflow/components/utilities/RunFlow.py +++ b/src/backend/langflow/components/utilities/RunFlow.py @@ -12,6 +12,7 @@ class RunFlowComponent(CustomComponent): def get_flow_names(self) -> List[str]: flow_records = self.list_flows() + self.flow_records = flow_records return [flow_record.data["name"] for flow_record in flow_records] def build_config(self): @@ -20,7 +21,7 @@ class RunFlowComponent(CustomComponent): "display_name": "Input Value", "multiline": True, }, - "flow_id": { + "flow": { "display_name": "Flow ID", "info": "The ID of the flow to run.", "options": self.get_flow_names, @@ -31,10 +32,17 @@ class RunFlowComponent(CustomComponent): }, } - async def build( - self, input_value: Text, flow_id: str, tweaks: NestedDict - ) -> Record: + async def build(self, input_value: Text, flow: str, tweaks: NestedDict) -> Record: input_dict = {"input_value": input_value} + flow_ids = [ + flow_record.data["id"] + for flow_record in self.flow_records + if flow_record.data["name"] == flow + ] + if not flow_ids: + raise ValueError(f"Flow {flow} not found.") + flow_id = flow_ids[0] + result: List[Optional[ResultData]] = await self.run_flow( input_value=input_dict, flow_id=flow_id, tweaks=tweaks )