From a23121aa5478be7a2c02a676697423fc3ce58701 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 15 Jun 2023 07:44:11 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(chat.py):=20yield=20error=20?= =?UTF-8?q?message=20when=20an=20exception=20occurs=20during=20stream=5Fbu?= =?UTF-8?q?ild=20=F0=9F=94=A7=20chore(base.py):=20fix=20typo=20in=20docstr?= =?UTF-8?q?ing=20The=20fix=20in=20chat.py=20ensures=20that=20an=20error=20?= =?UTF-8?q?message=20is=20yielded=20when=20an=20exception=20occurs=20durin?= =?UTF-8?q?g=20stream=5Fbuild.=20This=20helps=20to=20provide=20more=20info?= =?UTF-8?q?rmation=20to=20the=20client-side=20when=20an=20error=20occurs.?= =?UTF-8?q?=20The=20typo=20in=20base.py's=20docstring=20is=20fixed=20to=20?= =?UTF-8?q?improve=20readability.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/chat.py | 5 +++-- src/backend/langflow/graph/graph/base.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/api/v1/chat.py b/src/backend/langflow/api/v1/chat.py index 7acdf32ce..18f547682 100644 --- a/src/backend/langflow/api/v1/chat.py +++ b/src/backend/langflow/api/v1/chat.py @@ -107,8 +107,9 @@ async def stream_build(flow_id: str): yield f"data: {response}\n\n" chat_manager.set_cache(flow_id, graph.build()) - except Exception: - logger.error("Error while building the flow") + except Exception as exc: + logger.error("Error while building the flow: %s", exc) + yield f"data: {json.dumps({'error': str(exc)})}\n\n" finally: yield f"data: {final_response}\n\n" diff --git a/src/backend/langflow/graph/graph/base.py b/src/backend/langflow/graph/graph/base.py index ae4b37e2c..5cefdadae 100644 --- a/src/backend/langflow/graph/graph/base.py +++ b/src/backend/langflow/graph/graph/base.py @@ -10,6 +10,7 @@ from langflow.graph.vertex.types import ( ) from langflow.interface.tools.constants import FILE_TOOLS from langflow.utils import payload +from langflow.utils.logger import logger class Graph: @@ -30,7 +31,7 @@ class Graph: Creates a graph from a payload. Args: - payload (Dict): The payload to create the graph from. + payload (Dict): The payload to create the graph from.˜` Returns: Graph: The created graph.