| | |
| | | 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()) |
| | |
| | | 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 |
| | |
| | | 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 = [ |