Ver Fonte

毕昇消息过滤

zhangqian há 1 ano atrás
pai
commit
4d924ed03f
1 ficheiros alterados com 12 adições e 5 exclusões
  1. 12 5
      app/api/chat.py

+ 12 - 5
app/api/chat.py

@@ -65,7 +65,7 @@ async def handle_client(websocket: WebSocket,
                         except Exception as e:
                             result = {"message": f"内部错误: {e}", "type": "close"}
                             await websocket.send_json(result)
-                            print(f"Error forwarding message to ragflow: {e}")
+                            print(f"Error process message of ragflow: {e}")
             # 启动任务处理客户端消息
             tasks = [
                 asyncio.create_task(forward_to_ragflow())
@@ -88,7 +88,7 @@ async def handle_client(websocket: WebSocket,
                 async def forward_to_service():
                     while True:
                         message = await websocket.receive_json()
-                        print(f"Received from client {chat_id}: {message}")
+                        print(f"Received from client, {chat_id}: {message}")
                         # 添加 'agent_id' 和 'chat_id' 字段
                         message['flow_id'] = agent_id
                         message['chat_id'] = chat_id
@@ -105,9 +105,16 @@ async def handle_client(websocket: WebSocket,
                 async def forward_to_client():
                     while True:
                         message = await service_websocket.recv()
-                        print(f"Received from service S: {message}")
-                        await websocket.send_text(message)
-                        print(f"Forwarded to client {chat_id}: {message}")
+                        print(f"Received from bisheng: {message}")
+                        data = json.loads(message)
+                        if data["type"] == "close" or data["type"] == "stream" or data["type"] == "end_cover":
+                            if data["type"] == "close":
+                                t = "close"
+                            else:
+                                t = "stream"
+                            result = {"message": data["message"], "type": t}
+                            await websocket.send_json(result)
+                            print(f"Forwarded to client, {chat_id}: {result}")
 
                 # 启动两个任务,分别处理客户端和服务端的消息
                 tasks = [