From 46e223745cebfedb78563ea3b671ec0f2cadbf0e Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期二, 07 一月 2025 10:22:11 +0800
Subject: [PATCH] 多余输出过滤

---
 app/api/chat.py |   28 ++++++++++++++++++++++------
 1 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/app/api/chat.py b/app/api/chat.py
index d223c69..0bdb796 100644
--- a/app/api/chat.py
+++ b/app/api/chat.py
@@ -1,6 +1,7 @@
 import json
 import re
 import uuid
+from copy import deepcopy
 
 from fastapi import WebSocket, WebSocketDisconnect, APIRouter, Depends
 import asyncio
@@ -531,7 +532,7 @@
                             workflow_dict = {}
                             if input["workflow_type"] == 1 or input["workflow_type"] == 2:
                                 async for rag_response in dify_service.workflow(input["token"], current_user.id, i):
-                                    # print(rag_response)
+                                    print(rag_response)
                                     try:
                                         if rag_response[:5] == "data:":
                                             # 濡傛灉鏄紝鍒欐埅鍙栨帀鍓�5涓瓧绗︼紝骞跺幓闄ら灏剧┖鐧界
@@ -544,7 +545,15 @@
                                         try:
                                             data = json.loads(complete_response)
                                             # print(data)
-                                            node_list.append(data)
+                                            node_data = deepcopy(data)
+                                            if "data" in node_data:
+                                                if "outputs" in node_data["data"]:
+                                                    node_data["data"]["outputs"] = {}
+                                                if "inputs" in node_data["data"]:
+                                                    node_data["data"]["inputs"] = {}
+                                            print(node_data)
+                                            node_list.append(node_data)
+
                                             complete_response = ""
                                             if data.get("event") == "node_started":  # "event": "message_end"
 
@@ -615,7 +624,7 @@
                                                                                               "conversation_id"))
                                                         node_list = []
                                                     except Exception as e:
-                                                        logger.error("淇濆瓨dify鐨勪細璇濆紓甯革紒")
+                                                        logger.error("淇濆瓨dcd ify鐨勪細璇濆紓甯革紒")
                                                         logger.error(e)
                                                     try:
                                                         await websocket.send_json(result)
@@ -623,7 +632,7 @@
                                                         logger.error(e)
                                                         logger.error("杩斿洖瀹㈡埛绔秷鎭紓甯�!")
 
-                                                    result = {"message": "", "type": "close", "workflow": workflow_dict, "is_next": is_next}
+                                                    result = {"message": "", "type": "close", "workflow": workflow_dict, "is_next": is_next, "download_url": download_url}
 
 
                                             else:
@@ -634,6 +643,7 @@
                                                 logger.error(e)
                                                 logger.error("杩斿洖瀹㈡埛绔秷鎭紓甯�!")
                                             complete_response = ""
+
                                         except json.JSONDecodeError as e:
                                             print(f"Error decoding JSON: {e}")
                                             # print(f"Response text: {text}")
@@ -660,8 +670,14 @@
                                             complete_response += rag_response
                                         try:
                                             data = json.loads(complete_response)
-                                            node_list.append(data)
-                                            # print(data)
+                                            node_data = deepcopy(data)
+                                            if "data" in node_data:
+                                                if "outputs" in node_data["data"]:
+                                                    node_data["data"]["outputs"] = {}
+                                                if "inputs" in node_data["data"]:
+                                                    node_data["data"]["inputs"] = {}
+                                            print(node_data)
+                                            node_list.append(node_data)
                                             complete_response = ""
                                             if data.get("event") == "node_started":  # "event": "message_end"
                                                 if "data" not in data or not data["data"]:  # 淇℃伅杩囨护

--
Gitblit v1.8.0