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/agent.py | 54 +++++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 45 insertions(+), 9 deletions(-)
diff --git a/app/api/agent.py b/app/api/agent.py
index 98ee2cb..f3ea907 100644
--- a/app/api/agent.py
+++ b/app/api/agent.py
@@ -143,14 +143,14 @@
elif 'report_name' in message_json:
message = message_json['report_name']
- except json.JSONDecodeError:
+ except Exception as e:
pass # 闈� JSON 瀛楃涓诧紝缁х画浣跨敤鍘熷 message
if session.get('files') and isinstance(session.get('files'), str):
try:
files = json.loads(session.get('files'))
process_files(files, agent_id)
- except json.JSONDecodeError:
+ except Exception as e:
pass # 闈� JSON 瀛楃涓诧紝缁х画浣跨敤鍘熷 message
# 妫�鏌� message 鏄惁涓� None
@@ -223,17 +223,51 @@
for i in session.log_to_json().get("message", []):
if i.get("role") == "user":
tmp_data["question"] = i.get("content")
+ if "type" in i.get("content"):
+ tmp_data["type"] = i.get("content")["type"]
elif i.get("role") == "assistant":
if isinstance(i.get("content"), dict):
- tmp_data["answer"] = i.get("content", {}).get("answer")
- if "file_name" in i.get("content", {}):
- tmp_data["files"] = [{"file_name": i.get("content", {}).get("file_name"),
- "file_url": i.get("content", {}).get("file_url")}]
+ content = i.get("content", {})
+ tmp_data["answer"] = content.get("answer")
+ if "file_name" in content:
+ tmp_data["files"] = [{"file_name": content.get("file_name"),
+ "file_url": content.get("file_url")}]
if "images" in i.get("content", {}):
- tmp_data["images"] = i.get("content", {}).get("images")
+ tmp_data["images"] = content.get("images")
- if "download_url" in i.get("content", {}):
- tmp_data["download_url"] = i.get("content", {}).get("download_url")
+ if "download_url" in content:
+ tmp_data["download_url"] = content.get("download_url")
+
+ if "node_list" in content:
+ node_dict = {
+ "node_data": [], # {"title": "鍘婚櫎鍐椾綑", # 鑺傜偣鍚嶇О "status": "succeeded", # 鑺傜偣鐘舵��"created_at": 1735817337, # 寮�濮嬫椂闂�"finished_at": 1735817337, # 缁撴潫鏃堕棿"error": "" # 閿欒鏃ュ織}
+ "total_tokens": 0, # 鑺辫垂token鏁�
+ "created_at": 0, # 寮�濮嬫椂闂�
+ "finished_at": 0, # 缁撴潫鏃堕棿
+ "elapsed_time": 0, # 缁撴潫鏃堕棿
+ "status": "succeeded", # 宸ヤ綔娴佺姸鎬�
+ "error": "", # 閿欒鏃ュ織
+ }
+ for node in content["node_list"]:
+ if node.get("event") == "node_finished":
+ node_dict["node_data"].append({
+ "title": node.get("data", {}).get("title", ""),
+ "status": node.get("data", {}).get("status", ""),
+ "created_at":node.get("data", {}).get("created_at", 0),
+ "finished_at":node.get("data", {}).get("finished_at", 0),
+ "node_type":node.get("data", {}).get("node_type", 0),
+ "elapsed_time":node.get("data", {}).get("elapsed_time", 0),
+ "error":node.get("data", {}).get("error", ""),
+ })
+ elif node.get("event") == "workflow_finished":
+ node_dict["total_tokens"] = node.get("data", {}).get("total_tokens", 0)
+ node_dict["created_at"] = node.get("data", {}).get("created_at", 0)
+ node_dict["finished_at"] = node.get("data", {}).get("finished_at", 0)
+ node_dict["status"] = node.get("data", {}).get("status", "")
+ node_dict["error"] = node.get("data", {}).get("error", "")
+ node_dict["elapsed_time"] = node.get("data", {}).get("elapsed_time", 0)
+ tmp_data["workflow"] = node_dict
+
else:
tmp_data["answer"] = i.get("content")
data.append(tmp_data)
@@ -255,3 +289,5 @@
return Response(code=404, msg="Agent not found")
return Response(code=200, msg="", data={"chat_id": uuid.uuid4().hex})
+
+
--
Gitblit v1.8.0