Support returning sub flow outputs (#2177)
Add support for returning outputs from running flow as records
This commit is contained in:
parent
dfc008b383
commit
71de94f65e
2 changed files with 25 additions and 2 deletions
|
|
@ -1,5 +1,7 @@
|
|||
from typing import List
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from langflow.graph.schema import ResultData, RunOutputs
|
||||
from langflow.schema import Record
|
||||
|
||||
|
|
@ -37,9 +39,29 @@ def build_records_from_result_data(result_data: ResultData, get_final_results_on
|
|||
|
||||
"""
|
||||
messages = result_data.messages
|
||||
if not messages:
|
||||
return []
|
||||
records = []
|
||||
|
||||
# Handle results without chat messages (calling flow)
|
||||
if not messages:
|
||||
# Result with a single record
|
||||
if isinstance(result_data.artifacts, dict):
|
||||
records.append(Record(data=result_data.artifacts))
|
||||
# List of artifacts
|
||||
elif isinstance(result_data.artifacts, list):
|
||||
for artifact in result_data.artifacts:
|
||||
# If multiple records are found as artifacts, return as-is
|
||||
if isinstance(artifact, Record):
|
||||
records.append(artifact)
|
||||
else:
|
||||
# Warn about unknown output type
|
||||
logger.warning(f"Unable to build record output from unknown ResultData.artifact: {str(artifact)}")
|
||||
# Chat or text output
|
||||
elif result_data.results:
|
||||
records.append(Record(data={"result": result_data.results}, text_key="result"))
|
||||
return records
|
||||
else:
|
||||
return []
|
||||
|
||||
for message in messages:
|
||||
message_dict = message if isinstance(message, dict) else message.model_dump()
|
||||
if get_final_results_only:
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ INPUT_COMPONENTS = [
|
|||
OUTPUT_COMPONENTS = [
|
||||
InterfaceComponentTypes.ChatOutput,
|
||||
InterfaceComponentTypes.TextOutput,
|
||||
InterfaceComponentTypes.RecordsOutput,
|
||||
]
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue