From 4ad226f35b33ccbdacae87fd1f47cd09a1dd38e2 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 28 Jul 2023 11:24:16 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9A=20docs(custom-component.mdx):=20re?= =?UTF-8?q?move=20unnecessary=20code=20and=20examples=20from=20the=20custo?= =?UTF-8?q?m=20component=20guidelines=20=F0=9F=93=9A=20docs(custom-compone?= =?UTF-8?q?nt.mdx):=20remove=20unnecessary=20code=20and=20examples=20relat?= =?UTF-8?q?ed=20to=20the=20FlowRunner=20component=20from=20the=20custom=20?= =?UTF-8?q?component=20guidelines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/docs/guidelines/custom-component.mdx | 238 ---------------------- 1 file changed, 238 deletions(-) diff --git a/docs/docs/guidelines/custom-component.mdx b/docs/docs/guidelines/custom-component.mdx index e6ad8c17b..23a276094 100644 --- a/docs/docs/guidelines/custom-component.mdx +++ b/docs/docs/guidelines/custom-component.mdx @@ -340,241 +340,3 @@ And here is our brand new custom component: justifyContent: "center", }} /> - -## FlowRunner Example - -Now let's see how to create a component that runs other flows. - - - -```python -from langflow.interface.custom.custom_component import CustomComponent - -class MyComponent(CustomComponent): - display_name = "Custom Component" - - def build_config(self): - ... - - def build(self): - ... - -``` - -This is the basic structure of a custom component. - ---- - -```python -from langflow.interface.custom.custom_component import CustomComponent - -# focus -class FlowRunner(CustomComponent): - # focus - display_name = "Flow Runner" - # focus - description = "Run other flows" - - def build_config(self): - ... - - def build(self): - ... - -``` - -So, let's start by adding the _`display_name`_ and a _`description`_. - ---- - -```python -from langflow.interface.custom.custom_component import CustomComponent -# focus -from langchain.schema import Document - - -class FlowRunner(CustomComponent): - - display_name = "Flow Runner" - - description = "Run other flows" - - def build_config(self): - ... - - def build(self): - ... - -``` - -Now let's import Document from the schema module, which will be our return type for the _`build`_ method. - ---- - -```python -from langflow.interface.custom.custom_component import CustomComponent -from langchain.schema import Document - -class FlowRunner(CustomComponent): - display_name = "Flow Runner" - description = "Run other flows using a document as input." - - def build_config(self): - ... - - # focus - def build(self, flow_name: str, document: Document) -> Document: - ... - -``` - -Let's add the [parameters](focus://11[20:55]) and the [return type](focus://11[60:69]) to the _`build`_ method. - ---- - -```python -from langflow.interface.custom.custom_component import CustomComponent -from langchain.schema import Document - - -class FlowRunner(CustomComponent): - - display_name = "Flow Runner" - - description = "Run other flows using a document as input." - - def build_config(self): - ... - - def build(self, flow_name: str, document: Document) -> Document: - # focus - # List the flows - # focus - flows = self.list_flows() - -``` - ---- - -```python -from langflow.interface.custom.custom_component import CustomComponent -from langchain.schema import Document - - -class FlowRunner(CustomComponent): - - display_name = "Flow Runner" - - description = "Run other flows using a document as input." - - def build_config(self): - ... - - 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)) - -``` - -With the _`list_flows`_ method, we can get a list of all the flows in the collection. - -We can then get the flow that matches the selected name. - ---- - -```python -from langflow.interface.custom.custom_component import CustomComponent -from langchain.schema import Document - - -class FlowRunner(CustomComponent): - - display_name = "Flow Runner" - - description = "Run other flows using a document as input." - - def build_config(self): - ... - - 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)) - # focus - # Load the flow - # focus - tweaks = {} - # focus - flow = self.load_flow(flow.id, tweaks) - -``` - ---- - -```python -from langflow.interface.custom.custom_component import CustomComponent -from langchain.schema import Document - - -class FlowRunner(CustomComponent): - - display_name = "Flow Runner" - - description = "Run other flows using a document as input." - - def build_config(self): - ... - - 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)) - # Load the flow - tweaks = {} - flow = self.load_flow(flow.id, tweaks) - # focus - # Get the page_content from the document - # focus - page_content = document.page_content -``` - ---- - -```python -from langflow.interface.custom.custom_component import CustomComponent -from langchain.schema import Document - - -class FlowRunner(CustomComponent): - - display_name = "Flow Runner" - - description = "Run other flows using a document as input." - - def build_config(self): - ... - - 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)) - # Load the flow - tweaks = {} - flow = self.load_flow(flow.id, tweaks) - # Get the page_content from the document - page_content = document.page_content - # Use it in the flow - result = flow(page_content) - return Document(page_content=str(result)) -``` - ---- - -