From b2979bce1722c1dcb5aa5bb7e493e1d1441ecba0 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 31 Jul 2023 16:03:51 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(flow-runner.mdx):=20remove?= =?UTF-8?q?=20unnecessary=20load=5Fflow=20calls=20and=20update=20get=5Fflo?= =?UTF-8?q?w=20method=20signature=20to=20include=20tweaks=20parameter=20?= =?UTF-8?q?=F0=9F=9A=9A=20chore(flow-runner.mdx):=20update=20load=5Fflow?= =?UTF-8?q?=20references=20to=20get=5Fflow=20=F0=9F=9A=9A=20chore(flow-run?= =?UTF-8?q?ner.mdx):=20remove=20commented=20out=20code=20=F0=9F=9A=9A=20ch?= =?UTF-8?q?ore(flow-runner.mdx):=20update=20load=5Fflow=20references=20to?= =?UTF-8?q?=20get=5Fflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docs/examples/flow-runner.mdx | 24 +++++++------------ .../interface/custom/custom_component.py | 13 ++++++++-- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/docs/docs/examples/flow-runner.mdx b/docs/docs/examples/flow-runner.mdx index bcf2b9dd1..eca31d21e 100644 --- a/docs/docs/examples/flow-runner.mdx +++ b/docs/docs/examples/flow-runner.mdx @@ -57,10 +57,8 @@ description = "Run other flows using a document as input." # Get the flow that matches the selected name # You can also get the flow by id # using self.get_flow(flow_id=flow_id) - flow = self.get_flow(flow_name=flow_name) - # Load the flow tweaks = {} - flow = self.load_flow(flow.id, tweaks) + flow = self.get_flow(flow_name=flow_name, tweaks=tweaks) # Get the page_content from the document page_content = document.page_content # Use it in the flow @@ -205,7 +203,8 @@ class FlowRunner(CustomComponent): # Get the flow that matches the selected name # You can also get the flow by id # using self.get_flow(flow_id=flow_id) - flow = self.get_flow(flow_name=flow_name) + tweaks = {} + flow = self.get_flow(flow_name=flow_name, tweaks=tweaks) ``` @@ -237,17 +236,13 @@ class FlowRunner(CustomComponent): # Get the flow that matches the selected name # You can also get the flow by id # using self.get_flow(flow_id=flow_id) - flow = self.get_flow(flow_name=flow_name) - # focus - # Load the flow - # focus tweaks = {} - # focus - flow = self.load_flow(flow.id, tweaks) + flow = self.get_flow(flow_name=flow_name, tweaks=tweaks) + ``` -You can load this flow using _`load_flow`_ and set a _`tweaks`_ dictionary to customize it. Find more about tweaks in our [features guidelines](../guidelines/features#code). +You can load this flow using _`get_flow`_ and set a _`tweaks`_ dictionary to customize it. Find more about tweaks in our [features guidelines](../guidelines/features#code). --- @@ -269,10 +264,8 @@ class FlowRunner(CustomComponent): # Get the flow that matches the selected name # You can also get the flow by id # using self.get_flow(flow_id=flow_id) - flow = self.get_flow(flow_name=flow_name) - # Load the flow tweaks = {} - flow = self.load_flow(flow.id, tweaks) + flow = self.get_flow(flow_name=flow_name, tweaks=tweaks) # Get the page_content from the document page_content = document.page_content # Use it in the flow @@ -313,10 +306,9 @@ class FlowRunner(CustomComponent): # Get the flow that matches the selected name # You can also get the flow by id # using self.get_flow(flow_id=flow_id) - flow = self.get_flow(flow_name=flow_name) # Load the flow tweaks = {} - flow = self.load_flow(flow.id, tweaks) + flow = self.get_flow(flow_name=flow_name, tweaks=tweaks) # Get the page_content from the document page_content = document.page_content # Use it in the flow diff --git a/src/backend/langflow/interface/custom/custom_component.py b/src/backend/langflow/interface/custom/custom_component.py index fc8efcc5d..9218a3e1b 100644 --- a/src/backend/langflow/interface/custom/custom_component.py +++ b/src/backend/langflow/interface/custom/custom_component.py @@ -159,14 +159,23 @@ class CustomComponent(Component, extra=Extra.allow): return flows def get_flow( - self, *, flow_name: Optional[str] = None, flow_id: Optional[str] = None + self, + *, + flow_name: Optional[str] = None, + flow_id: Optional[str] = None, + tweaks: Optional[dict] = None, ) -> Flow: with session_getter() as session: if flow_id: flow = session.query(Flow).get(flow_id) elif flow_name: flow = session.query(Flow).filter(Flow.name == flow_name).first() - return flow + else: + raise ValueError("Either flow_name or flow_id must be provided") + + if not flow: + raise ValueError(f"Flow {flow_name or flow_id} not found") + return self.load_flow(flow.id, tweaks) def build(self): raise NotImplementedError