From 6953ae89c42c6b237166e6a02af64469cc2bfae5 Mon Sep 17 00:00:00 2001 From: Stephen Hu Date: Thu, 5 Jun 2025 15:14:15 +0800 Subject: [PATCH] =?UTF-8?q?Fix:when=20stream=3Dfalse=EF=BC=8Cnew=20message?= =?UTF-8?q?=20without=20sessionid=20does=20no=20=20(#8078)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What problem does this PR solve? https://github.com/infiniflow/ragflow/issues/8070 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- api/db/services/conversation_service.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/api/db/services/conversation_service.py b/api/db/services/conversation_service.py index c37812937..5e247c21c 100644 --- a/api/db/services/conversation_service.py +++ b/api/db/services/conversation_service.py @@ -90,17 +90,18 @@ def completion(tenant_id, chat_id, question, name="New session", session_id=None "user_id": kwargs.get("user_id", "") } ConversationService.save(**conv) - yield "data:" + json.dumps({"code": 0, "message": "", - "data": { - "answer": conv["message"][0]["content"], - "reference": {}, - "audio_binary": None, - "id": None, - "session_id": session_id - }}, - ensure_ascii=False) + "\n\n" - yield "data:" + json.dumps({"code": 0, "message": "", "data": True}, ensure_ascii=False) + "\n\n" - return + if stream: + yield "data:" + json.dumps({"code": 0, "message": "", + "data": { + "answer": conv["message"][0]["content"], + "reference": {}, + "audio_binary": None, + "id": None, + "session_id": session_id + }}, + ensure_ascii=False) + "\n\n" + yield "data:" + json.dumps({"code": 0, "message": "", "data": True}, ensure_ascii=False) + "\n\n" + return conv = ConversationService.query(id=session_id, dialog_id=chat_id) if not conv: