From 16935ec1981b064785409c2a20a4f98fdfaa0d90 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 31 Jul 2023 10:50:49 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(flow-runner.mdx):=20fix=20br?= =?UTF-8?q?oken=20link=20to=20langchain.schema=20module=20in=20import=20st?= =?UTF-8?q?atement=20=F0=9F=90=9B=20fix(flow-runner.mdx):=20remove=20unnec?= =?UTF-8?q?essary=20focus=20annotations=20in=20code=20snippets=20=E2=9C=A8?= =?UTF-8?q?=20feat(flow-runner.mdx):=20add=20support=20for=20getting=20flo?= =?UTF-8?q?w=20by=20name=20instead=20of=20id=20in=20build=20method=20?= =?UTF-8?q?=E2=9C=A8=20feat(flow-runner.mdx):=20add=20caution=20about=20un?= =?UTF-8?q?ique=20flow=20names=20in=20version=200.4.0=20=E2=9C=A8=20feat(f?= =?UTF-8?q?low-runner.mdx):=20add=20support=20for=20passing=20document=20p?= =?UTF-8?q?arameter=20in=20build=20method=20=F0=9F=90=9B=20fix(flow-runner?= =?UTF-8?q?.mdx):=20remove=20redundant=20Optional=20type=20hint=20for=20do?= =?UTF-8?q?cument=20parameter=20in=20build=20method=20=F0=9F=90=9B=20fix(f?= =?UTF-8?q?low-runner.mdx):=20remove=20empty=20line=20at=20the=20end=20of?= =?UTF-8?q?=20the=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docs/examples/flow-runner.mdx | 39 +++++++++++++++++------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/docs/docs/examples/flow-runner.mdx b/docs/docs/examples/flow-runner.mdx index ddcee5f40..846a5b186 100644 --- a/docs/docs/examples/flow-runner.mdx +++ b/docs/docs/examples/flow-runner.mdx @@ -90,7 +90,7 @@ class FlowRunner(CustomComponent): ``` -Second, we will import _`Document`_ from the [*langchain.schema*](https://docs.langchain.com/docs/components/schema/) module. This will be the return type of the _`build`_ method. +Second, we will import _`Document`_ from the [_langchain.schema_](https://docs.langchain.com/docs/components/schema/) module. This will be the return type of the _`build`_ method. --- @@ -120,7 +120,7 @@ Now, let's add the [parameters](focus://11[20:55]) and the [return type](focus:/ --- -```python +```python focus=13:14 from langflow import CustomComponent from langchain.schema import Document @@ -133,9 +133,7 @@ class FlowRunner(CustomComponent): ... def build(self, flow_name: str, document: Document) -> Document: - # focus # List the flows - # focus flows = self.list_flows() ``` @@ -144,7 +142,7 @@ We can now start writing the _`build`_ method. Let's list available flows in "My --- -```python +```python focus=15:18 from langflow import CustomComponent from langchain.schema import Document @@ -159,17 +157,19 @@ class FlowRunner(CustomComponent): def build(self, flow_name: str, document: Document) -> Document: # List the flows flows = self.list_flows() - # focus # Get the flow that matches the selected name - # focus - flow = next(filter(lambda f: f.name == flow_name, flows)) + # You can also get the flow by id + # using self.get_flow(flow_id=flow_id) + flow = self.get_flow(flow_name=flow_name) ``` And retrieve a flow that matches the selected name (we'll make a dropdown input field for the user to choose among flow names). - From version 0.4.0, names are unique, which was not the case in previous versions. This might lead to unexpected results if using flows with the same name. + From version 0.4.0, names are unique, which was not the case in previous + versions. This might lead to unexpected results if using flows with the same + name. --- @@ -190,7 +190,9 @@ class FlowRunner(CustomComponent): # List the flows flows = self.list_flows() # Get the flow that matches the selected name - flow = next(filter(lambda f: f.name == flow_name, flows)) + # 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 @@ -220,7 +222,9 @@ class FlowRunner(CustomComponent): # List the flows flows = self.list_flows() # Get the flow that matches the selected name - flow = next(filter(lambda f: f.name == flow_name, flows)) + # 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) @@ -255,11 +259,13 @@ class FlowRunner(CustomComponent): } - def build(self, flow_name: str, document: Optional[Document] = None) -> Document: + def build(self, flow_name: str, document: Document) -> Document: # List the flows flows = self.list_flows() # Get the flow that matches the selected name - flow = next(filter(lambda f: f.name == flow_name, flows)) + # 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) @@ -282,7 +288,6 @@ Finally, we can add field customizations through the _`build_config`_ method. He Done! This is what our script and custom component look like: -
- - -
\ No newline at end of file + +