From 9c574e1e666e976ab2552691a3b2df8fb448d1d2 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期四, 17 十月 2024 21:37:51 +0800 Subject: [PATCH] 解决发第二条消息报错问题 --- app/api/chat.py | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-) diff --git a/app/api/chat.py b/app/api/chat.py index 7381aab..a847431 100644 --- a/app/api/chat.py +++ b/app/api/chat.py @@ -46,16 +46,19 @@ message = await websocket.receive_json() print(f"Received from client {chat_id}: {message}") chat_history = message.get('chatHistory', []) + message["role"] = "user" if len(chat_history) == 0: chat_history = await ragflow_service.get_session_history(token, chat_id) if len(chat_history) == 0: chat_history = await ragflow_service.set_session(token, agent_id, - message["message"], chat_id, True) + message, chat_id, True) if len(chat_history) == 0: result = {"message": "鍐呴儴閿欒锛氬垱寤轰細璇濆け璐�", "type": "close"} await websocket.send_json(result) await websocket.close() return + else: + chat_history.append(message) 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