From f8f78ac0596a80755c9757d4ef888ea8eacd0c68 Mon Sep 17 00:00:00 2001 From: puzhen <1303385763@qq.com> Date: Tue, 21 Oct 2025 11:01:32 +0100 Subject: [PATCH] update --- backend/app/service/chat_service.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/backend/app/service/chat_service.py b/backend/app/service/chat_service.py index be46a4f6e..973a7c43c 100644 --- a/backend/app/service/chat_service.py +++ b/backend/app/service/chat_service.py @@ -1,5 +1,6 @@ import asyncio import datetime +import json from pathlib import Path import platform from typing import Literal @@ -829,11 +830,22 @@ Based on the user query, determine the type and provide appropriate response.""" content = resp.msgs[0].content if not content: return True - normalized = content.strip().lower() - if normalized in ["yes", "complex"]: - return True - return sse_json("wait_confirm", {"content": content, "question": prompt}) - + content_stripped = content.strip() + if content_stripped.startswith('{') and content_stripped.endswith('}'): + try: + parsed_json = json.loads(content_stripped) + result = QuestionAnalysisResult(**parsed_json) + except (json.JSONDecodeError, ValueError) as e: + logger.warning(f"Failed to parse JSON from content: {e}") + normalized = content.strip().lower() + if normalized in ["yes", "complex"]: + return True + return sse_json("wait_confirm", {"content": content, "question": prompt}) + else: + normalized = content.strip().lower() + if normalized in ["yes", "complex"]: + return True + return sse_json("wait_confirm", {"content": content, "question": prompt}) if result.type == "simple" and result.answer: return sse_json("wait_confirm", {"content": result.answer, "question": prompt}) else: