🐛 fix(flow-runner.mdx): handle case where document is a list and extract the first element to ensure compatibility with the flow

🔨 refactor(flow-runner.mdx): remove unnecessary comment and unused variable to improve code readability and maintainability
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-07-31 21:42:08 -03:00
commit 2f9ffd1d48

View file

@ -60,6 +60,8 @@ description = "Run other flows using a document as input."
tweaks = {}
flow = self.get_flow(flow_name=flow_name, tweaks=tweaks)
# Get the page_content from the document
if document and isinstance(document, list):
document = document[0]
page_content = document.page_content
# Use it in the flow
result = flow(page_content)
@ -267,6 +269,8 @@ class FlowRunner(CustomComponent):
tweaks = {}
flow = self.get_flow(flow_name=flow_name, tweaks=tweaks)
# Get the page_content from the document
if document and isinstance(document, list):
document = document[0]
page_content = document.page_content
# Use it in the flow
result = flow(page_content)
@ -299,17 +303,17 @@ class FlowRunner(CustomComponent):
"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)
# Load the flow
tweaks = {}
flow = self.get_flow(flow_name=flow_name, tweaks=tweaks)
# Get the page_content from the document
if document and isinstance(document, list):
document = document[0]
page_content = document.page_content
# Use it in the flow
result = flow(page_content)