diff --git a/docs/docs/examples/flow-runner.mdx b/docs/docs/examples/flow-runner.mdx index 846a5b186..ffa4d2e2e 100644 --- a/docs/docs/examples/flow-runner.mdx +++ b/docs/docs/examples/flow-runner.mdx @@ -29,6 +29,48 @@ We will cover how to: - Load a flow using the _`load_flow`_ method. - Configure a dropdown input field using the _`options`_ parameter. +
+ +Example Code + +```python +from langflow 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): + flows = self.list_flows() + flow_names = [f.name for f in flows] + return {"flow_name": {"options": flow_names, + "display_name": "Flow Name", + }, + "document": {"display_name": "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 + # 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) + # 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)) + +``` + +
+ ```python @@ -282,8 +324,6 @@ Finally, we can add field customizations through the _`build_config`_ method. He Make sure that the field type is _`str`_ and _`options`_ values are strings. ---- - Done! This is what our script and custom component look like: