📚 docs(custom-component.mdx): remove unnecessary code and examples from the custom component guidelines
📚 docs(custom-component.mdx): remove unnecessary code and examples related to the FlowRunner component from the custom component guidelines
This commit is contained in:
parent
457453656a
commit
4ad226f35b
1 changed files with 0 additions and 238 deletions
|
|
@ -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.
|
||||
|
||||
<CH.Scrollycoding rows={20} className={""}>
|
||||
|
||||
```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))
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
</CH.Scrollycoding>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue