fix: Handle DataFrame serialization and export in langflow.io (#4956)

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-11-30 15:15:03 -03:00 committed by GitHub
commit ee37ce04ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View file

@ -1,6 +1,7 @@
from langflow.inputs import (
BoolInput,
CodeInput,
DataFrameInput,
DataInput,
DefaultPromptField,
DictInput,
@ -50,4 +51,5 @@ __all__ = [
"SliderInput",
"StrInput",
"TableInput",
"DataFrameInput",
]

View file

@ -6,6 +6,7 @@ from pydantic import BaseModel
from typing_extensions import TypedDict
from langflow.schema.data import Data
from langflow.schema.dataframe import DataFrame
from langflow.schema.message import Message
from langflow.schema.serialize import recursive_serialize_or_str
@ -51,7 +52,7 @@ def get_type(payload):
case dict():
result = LogType.OBJECT
case list():
case list() | DataFrame():
result = LogType.ARRAY
case str():
@ -107,6 +108,8 @@ def build_output_logs(vertex, result) -> dict:
message = ""
case LogType.ARRAY:
if isinstance(message, DataFrame):
message = message.to_dict(orient="records")
message = [recursive_serialize_or_str(item) for item in message]
name = output.get("name", f"output_{index}")
outputs |= {name: OutputValue(message=message, type=_type).model_dump()}