| | |
| | | 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, # 结束时间 |
| | | "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) |
| | |
| | | return Response(code=404, msg="Agent not found") |
| | | |
| | | return Response(code=200, msg="", data={"chat_id": uuid.uuid4().hex}) |
| | | |
| | | |