소스 검색

解决发第二条消息报错问题

zhangqian 1 년 전
부모
커밋
9c574e1e66
1개의 변경된 파일3개의 추가작업 그리고 5개의 파일을 삭제
  1. 3 5
      app/api/chat.py

+ 3 - 5
app/api/chat.py

@@ -46,21 +46,19 @@ async def handle_client(websocket: WebSocket,
                     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({
-                                "content": message["message"],
-                                "role": "user"
-                            })
+                            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}")