From 4d924ed03fb1f518353fb31ce3c1dab4eefc0a95 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期一, 14 十月 2024 14:52:23 +0800
Subject: [PATCH] 毕昇消息过滤

---
 app/api/chat.py |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/app/api/chat.py b/app/api/chat.py
index 9bd22b9..7667736 100644
--- a/app/api/chat.py
+++ b/app/api/chat.py
@@ -65,7 +65,7 @@
                         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 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 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 = [

--
Gitblit v1.8.0