langflow icon indicating copy to clipboard operation
langflow copied to clipboard

Questions about Run Flow

Open alex-ge123 opened this issue 1 year ago • 3 comments

runflow calls other processes. How do I get the return value

微信图片_20240619155903

alex-ge123 avatar Jun 19 '24 07:06 alex-ge123

To get the return value from the "getToken" process called by the "Run Flow" component and use it in the "Records Output" component to display records as a table, follow these steps:

  1. Run the Flow: Use the RunFlowComponent to execute the flow and get the results.
  2. Process the Results: Convert the results into records using the build_records_from_result_data method.
  3. Display the Records: Use the processed records in the "Records Output" component to display them as a table.

Here is an example of how you can achieve this:

from langflow.base.flow_processing.utils import build_records_from_run_outputs
from langflow.schema import Record
from langflow.components.experimental.RunFlow import RunFlowComponent
from langflow.custom import CustomComponent

# Assuming you have an instance of RunFlowComponent
run_flow_component = RunFlowComponent()

# Define the input parameters for the flow
input_value = "your_input_value"
flow_name = "your_flow_name"
tweaks = {}  # Any tweaks you want to apply

# Run the flow and get the results
results = await run_flow_component.build(input_value, flow_name, tweaks)

# Process the results to get records
if isinstance(results, list):
    records = []
    for result in results:
        if result:
            records.extend(run_flow_component.build_records_from_result_data(result))
else:
    records = run_flow_component.build_records_from_result_data(results)

# Now you can use these records in the "Records Output" component to display them as a table
class RecordOutput(CustomComponent):
    display_name = "Records Output"
    description = "Display Records as a Table"

    def build_config(self):
        return {
            "input_value": {
                "display_name": "Records",
                "input_types": ["Record"],
                "info": "Record or Record list to be passed as input.",
            },
        }

    def build(self, input_value: Record) -> Record:
        self.status = input_value
        return input_value

# Assuming you have a function to display records as a table
record_output_component = RecordOutput()
record_output_component.build(records)
display_records_as_table(record_output_component.status)

This code snippet demonstrates how to run the flow, process the results into records, and then use those records to display them in a table using the Records Output component [1][2][3].

To continue talking to Dosu, mention @dosu.

dosubot[bot] avatar Jun 19 '24 08:06 dosubot[bot]

Hi @alex-ge123, Could you please explain it in more detail? I didn't fully understand what you were trying to say.

anovazzi1 avatar Jul 01 '24 20:07 anovazzi1

Hi @alex-ge123 , 
 I hope you're doing well. Just a friendly reminder that if we do not hear back from you within the next 3 days, we will close this issue. If you need more time or further assistance, please let us know.


Thank you for your understanding!

carlosrcoelho avatar Jul 18 '24 13:07 carlosrcoelho

Thank you for your contribution! This issue will be closed. If you have any questions or encounter another problem, please open a new issue and we will be ready to assist you.

carlosrcoelho avatar Jul 22 '24 13:07 carlosrcoelho