From 5d1c58ae9062ae3387e1271b4ff48432020ab149 Mon Sep 17 00:00:00 2001 From: ytqh Date: Sun, 16 Mar 2025 21:12:36 +0800 Subject: [PATCH] handle invalid json output --- api/schedule/user_profile_generate_task.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/schedule/user_profile_generate_task.py b/api/schedule/user_profile_generate_task.py index f8293f621e..6d4e7de4fb 100644 --- a/api/schedule/user_profile_generate_task.py +++ b/api/schedule/user_profile_generate_task.py @@ -227,6 +227,11 @@ def process_user_health_summary(user: EndUser, new_messages: str): import json result = response["data"]["outputs"]["result"] + + # preprocess result in case of ```json xxxx``` + if result.startswith("```json") or result.endswith("```"): + result = result.strip("```json").strip("```") + result = json.loads(result) if "health_status" in result: user.health_status = result["health_status"]