From b4acf278db581ce5e70b513407b70db2d9b29b23 Mon Sep 17 00:00:00 2001
From: zhaoqingang <zhaoqg0118@163.com>
Date: 星期二, 07 一月 2025 17:33:32 +0800
Subject: [PATCH] 报告生成
---
app/api/chat.py | 38 ++++++++++++++++++++++++++++++--------
1 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/app/api/chat.py b/app/api/chat.py
index d223c69..571ebad 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
@@ -423,9 +424,7 @@
print(f"Error process message of ragflow: {e2}")
elif agent.type == "reportWorkflow":
- token = DfTokenDao(db).get_token_by_id(DOCUMENT_TO_CLEANING)
- if not token:
- await websocket.send_json({"message": "Invalid token document_to_cleaning", "type": "error"})
+
while True:
receive_message = await websocket.receive_json()
print(f"Received from client {chat_id}: {receive_message}")
@@ -479,6 +478,10 @@
inputs_list = []
is_next = 0
if workflow_type == 1:
+ token = DfTokenDao(db).get_token_by_id(DOCUMENT_TO_CLEANING)
+ if not token:
+ await websocket.send_json(
+ {"message": "Invalid token document_to_cleaning", "type": "error"})
inputs["input_files"] = files
inputs["Completion_of_main_indicators"] = title
inputs_list.append({"inputs": inputs, "token": token, "workflow_type": workflow_type})
@@ -501,6 +504,10 @@
{"message": "Invalid token document_to_title", "type": "error"})
inputs_list.append({"inputs": inputs, "token": token, "workflow_type": workflow_type})
elif workflow_type == 3 and is_clean == 1 or tokens >= max_token:
+ token = DfTokenDao(db).get_token_by_id(DOCUMENT_TO_CLEANING)
+ if not token:
+ await websocket.send_json(
+ {"message": "Invalid token document_to_cleaning", "type": "error"})
inputs["input_files"] = files
inputs["Completion_of_main_indicators"] = title
inputs_list.append({"inputs": inputs, "token": token, "workflow_type": 1})
@@ -544,7 +551,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 +630,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 +638,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 +649,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 +676,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