From f5f6ab74044362e44262c39b1b6e2a88a36e0f91 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 17 十月 2024 11:11:10 +0800
Subject: [PATCH] ragflow发送消息前查找消息历史并放到消息里

---
 app/api/chat.py |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/app/api/chat.py b/app/api/chat.py
index 458581a..fa53467 100644
--- a/app/api/chat.py
+++ b/app/api/chat.py
@@ -47,11 +47,14 @@
                     print(f"Received from client {chat_id}: {message}")
                     chat_history = message.get('chatHistory', [])
                     if len(chat_history) == 0:
-
-                        chat_history = await ragflow_service.set_session(token, agent_id, message["message"], chat_id, True)
+                        chat_history = await ragflow_service.get_session_history(token, agent_id)
                         if len(chat_history) == 0:
-                            result = {"message": "鍐呴儴閿欒锛氬垱寤轰細璇濆け璐�", "type": "close"}
-                            await websocket.send_json(result)
+                            chat_history = await ragflow_service.set_session(token, agent_id,
+                                                                             message["message"], chat_id, True)
+                            if len(chat_history) == 0:
+                                result = {"message": "鍐呴儴閿欒锛氬垱寤轰細璇濆け璐�", "type": "close"}
+                                await websocket.send_json(result)
+                                return
                     async for rag_response in ragflow_service.chat(token, chat_id, chat_history):
                         try:
                             print(f"Received from ragflow: {rag_response}")

--
Gitblit v1.8.0