Replies: 1 comment
-
To ensure that the result message is returned only once when calling a flow via API and receiving the chat data in def build_data_from_result_data(result_data: ResultData, get_final_results_only: bool = True) -> List[Data]:
"""
Build a list of data from the given ResultData.
Args:
result_data (ResultData): The ResultData object containing the result data.
get_final_results_only (bool, optional): Whether to include only final results. Defaults to True.
Returns:
List[Data]: A list of data built from the ResultData.
"""
messages = result_data.messages
if not messages:
return []
data = []
# Handle results without chat messages (calling flow)
if not messages:
# Result with a single record
if isinstance(result_data.artifacts, dict):
data.append(Data(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, Data):
data.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:
data.append(Data(data={"result": result_data.results}, text_key="result"))
return data
else:
return []
for message in messages: # type: ignore
message_dict = message if isinstance(message, dict) else message.model_dump()
if get_final_results_only:
result_data_dict = result_data.model_dump()
results = result_data_dict.get("results", {})
inner_result = results.get("result", {})
record = Data(data={"result": inner_result, "message": message_dict}, text_key="result")
data.append(record)
break # Ensure the message is added only once
return data By adding |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The data is returned 3 times:
In results.message
In artifacts.message
In outputs.message.message
How can only 1 result message?
Beta Was this translation helpful? Give feedback.
All reactions