From 907d9929e411cef4c61dd9b4d7368ba106de021e Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Tue, 26 Nov 2024 18:48:00 -0300 Subject: [PATCH] Fix: prevent infinity bug on agent (#4876) * Fix error handling and logging in build_flow function * Refactor: Update serialize_field function in utils.py This commit refactors the serialize_field function in utils.py to handle additional data types. It now properly serializes BaseModel objects and dictionaries by recursively calling the serialize_field function on their values. Additionally, it ensures that all other data types are converted to strings before returning. #4873 * update serialize --- src/backend/base/langflow/api/v1/chat.py | 4 ++++ src/backend/base/langflow/graph/utils.py | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/backend/base/langflow/api/v1/chat.py b/src/backend/base/langflow/api/v1/chat.py index ce31fdede..2ebe7d17e 100644 --- a/src/backend/base/langflow/api/v1/chat.py +++ b/src/backend/base/langflow/api/v1/chat.py @@ -409,6 +409,10 @@ async def build_flow( for task in tasks: task.cancel() return + except Exception as e: + logger.error(f"Error building vertices: {e}") + event_manager.on_error(data={"error": str(e)}) + raise event_manager.on_end(data={}) await event_manager.queue.put((None, None, time.time)) diff --git a/src/backend/base/langflow/graph/utils.py b/src/backend/base/langflow/graph/utils.py index 5ceee698b..4ad1b5235 100644 --- a/src/backend/base/langflow/graph/utils.py +++ b/src/backend/base/langflow/graph/utils.py @@ -79,14 +79,14 @@ def serialize_field(value): if isinstance(value, Document): return value.to_json() if isinstance(value, BaseModel): - return value.model_dump() + return serialize_field(value.model_dump()) + if isinstance(value, dict): + return {k: serialize_field(v) for k, v in value.items()} if isinstance(value, V1BaseModel): if hasattr(value, "to_json"): return value.to_json() return value.dict() - if isinstance(value, str): - return {"result": value} - return value + return str(value) def get_artifact_type(value, build_result) -> str: