From b476d0dd746207b4d20eb4008982282ef6c0d4be Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Fri, 16 Jun 2023 16:35:49 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(endpoints.py):=20add=20try-e?= =?UTF-8?q?xcept=20block=20when=20processing=20tweaks=20to=20catch=20and?= =?UTF-8?q?=20log=20exceptions=20=F0=9F=90=9B=20fix(process.py):=20fix=20K?= =?UTF-8?q?eyError=20when=20processing=20tweaks=20on=20graph=5Fdata=20with?= =?UTF-8?q?=20missing=20"data"=20key=20The=20try-except=20block=20added=20?= =?UTF-8?q?in=20endpoints.py=20catches=20any=20exceptions=20that=20occur?= =?UTF-8?q?=20when=20processing=20tweaks=20and=20logs=20them=20to=20the=20?= =?UTF-8?q?logger.=20This=20helps=20with=20debugging=20and=20identifying?= =?UTF-8?q?=20issues=20with=20the=20processing=20of=20tweaks.=20In=20proce?= =?UTF-8?q?ss.py,=20a=20KeyError=20was=20fixed=20by=20checking=20if=20the?= =?UTF-8?q?=20"data"=20key=20exists=20in=20the=20graph=5Fdata=20dictionary?= =?UTF-8?q?=20before=20accessing=20the=20"nodes"=20key.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/langflow/api/v1/endpoints.py | 6 ++++-- src/backend/langflow/processing/process.py | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/backend/langflow/api/v1/endpoints.py b/src/backend/langflow/api/v1/endpoints.py index e6bb08a12..6fea926d7 100644 --- a/src/backend/langflow/api/v1/endpoints.py +++ b/src/backend/langflow/api/v1/endpoints.py @@ -41,8 +41,10 @@ async def predict_flow( raise ValueError(f"Flow {flow_id} has no data") graph_data = flow.data if predict_request.tweaks: - graph_data = process_tweaks(graph_data, predict_request.tweaks) - + try: + graph_data = process_tweaks(graph_data, predict_request.tweaks) + except Exception as exc: + logger.error(f"Error processing tweaks: {exc}") response = process_graph_cached(graph_data, predict_request.message) return PredictResponse( result=response.get("result", ""), diff --git a/src/backend/langflow/processing/process.py b/src/backend/langflow/processing/process.py index deabe34dc..7f20371bc 100644 --- a/src/backend/langflow/processing/process.py +++ b/src/backend/langflow/processing/process.py @@ -179,7 +179,10 @@ def process_tweaks(graph_data: Dict, tweaks: Dict): # the dict of tweaks contains the name of a certain parameter and the value to be tweaked # We need to process the graph data to add the tweaks - nodes = graph_data["data"]["nodes"] + if "data" not in graph_data or "nodes" in graph_data["data"]: + nodes = graph_data["nodes"] + else: + nodes = graph_data["data"]["nodes"] for node in nodes: node_id = node["id"] if node_id in tweaks: