🐛 fix(endpoints.py): add try-except block when processing tweaks to catch and log exceptions

🐛 fix(process.py): fix KeyError when processing tweaks on graph_data with missing "data" key
The try-except block added in endpoints.py catches any exceptions that occur when processing tweaks and logs them to the logger. This helps with debugging and identifying issues with the processing of tweaks. In process.py, a KeyError was fixed by checking if the "data" key exists in the graph_data dictionary before accessing the "nodes" key.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-06-16 16:35:49 -03:00
commit b476d0dd74
2 changed files with 8 additions and 3 deletions

View file

@ -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", ""),

View file

@ -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: