From 2b3e826eb51b8645f50005e5f4927fd9e4b60a9e Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Mon, 14 Oct 2024 09:41:45 -0300 Subject: [PATCH 1/2] fix: enhance recursive_serialize_or_str to handle BaseModelV1 and improve exception logging (#4132) Enhance `recursive_serialize_or_str` to handle `BaseModelV1` and improve exception logging --- src/backend/base/langflow/schema/schema.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/backend/base/langflow/schema/schema.py b/src/backend/base/langflow/schema/schema.py index f73f2b00a0fe..9404863f3692 100644 --- a/src/backend/base/langflow/schema/schema.py +++ b/src/backend/base/langflow/schema/schema.py @@ -4,6 +4,7 @@ from loguru import logger from pydantic import BaseModel +from pydantic.v1 import BaseModel as BaseModelV1 from typing_extensions import TypedDict from langflow.schema import Data @@ -116,11 +117,13 @@ def build_output_logs(vertex, result) -> dict: def recursive_serialize_or_str(obj): try: + if isinstance(obj, str): + return obj if isinstance(obj, dict): return {k: recursive_serialize_or_str(v) for k, v in obj.items()} if isinstance(obj, list): return [recursive_serialize_or_str(v) for v in obj] - if isinstance(obj, BaseModel): + if isinstance(obj, BaseModel | BaseModelV1): if hasattr(obj, "model_dump"): obj_dict = obj.model_dump() elif hasattr(obj, "dict"): @@ -138,10 +141,10 @@ def recursive_serialize_or_str(obj): return {k: recursive_serialize_or_str(v) for k, v in obj.dict().items()} if hasattr(obj, "model_dump"): return {k: recursive_serialize_or_str(v) for k, v in obj.model_dump().items()} - if issubclass(obj, BaseModel): + if isinstance(obj, type) and issubclass(obj, BaseModel): # This a type BaseModel and not an instance of it return repr(obj) return str(obj) except Exception: # noqa: BLE001 - logger.opt(exception=True).debug(f"Cannot serialize object {obj}") + logger.debug(f"Cannot serialize object {obj}") return str(obj) From ba3bd8a8f266f14859edd466d33cd51e1b17518d Mon Sep 17 00:00:00 2001 From: dhlidongming Date: Mon, 14 Oct 2024 20:52:26 +0800 Subject: [PATCH 2/2] fix: name/description bug in "Flow as Tool" (#4097) Fix name/description bug in "Flow as Tool". --- .../base/langflow/components/prototypes/FlowTool.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/backend/base/langflow/components/prototypes/FlowTool.py b/src/backend/base/langflow/components/prototypes/FlowTool.py index 23f512cca2a9..7a4c0ee3b738 100644 --- a/src/backend/base/langflow/components/prototypes/FlowTool.py +++ b/src/backend/base/langflow/components/prototypes/FlowTool.py @@ -51,12 +51,12 @@ def update_build_config(self, build_config: dotdict, field_value: Any, field_nam name="flow_name", display_name="Flow Name", info="The name of the flow to run.", refresh_button=True ), StrInput( - name="name", + name="tool_name", display_name="Name", info="The name of the tool.", ), StrInput( - name="description", + name="tool_description", display_name="Description", info="The description of the tool.", ), @@ -89,8 +89,8 @@ def build_tool(self) -> Tool: logger.opt(exception=True).warning("Failed to set run_id") inputs = get_flow_inputs(graph) tool = FlowTool( - name=self.name, - description=self.description, + name=self.tool_name, + description=self.tool_description, graph=graph, return_direct=self.return_direct, inputs=inputs,