|
|
@@ -327,18 +327,43 @@ def _execute_and_get_result(
|
|
|
|
|
|
result = worker.execute(enhanced_query, backend_url, token)
|
|
|
chat_logger.info(f"Worker{worker_type}执行成功:问题{query}")
|
|
|
- ai_messages = [
|
|
|
- msg
|
|
|
- for msg in result.get("messages", [])
|
|
|
- if hasattr(msg, "type") and msg.type == "ai"
|
|
|
- ]
|
|
|
-
|
|
|
- if ai_messages:
|
|
|
- # 获取最后一条 AI 消息的内容
|
|
|
- last_ai_content = ai_messages[-1].content
|
|
|
- return last_ai_content
|
|
|
- else:
|
|
|
- return ""
|
|
|
+ last_ai_content = ""
|
|
|
+ all_messages = result["messages"]
|
|
|
+ for i, msg in enumerate(all_messages):
|
|
|
+ msg_data = {
|
|
|
+ "index": i,
|
|
|
+ "type": getattr(msg, "type", "unknown"),
|
|
|
+ "content": "",
|
|
|
+ }
|
|
|
+ # 获取内容
|
|
|
+ if hasattr(msg, "content"):
|
|
|
+ content = msg.content
|
|
|
+ if isinstance(content, str):
|
|
|
+ msg_data["content"] = content
|
|
|
+ else:
|
|
|
+ msg_data["content"] = str(content)
|
|
|
+
|
|
|
+ # 收集AI消息
|
|
|
+ if msg_data["type"] == "ai":
|
|
|
+ last_ai_content = msg_data["content"]
|
|
|
+
|
|
|
+ return last_ai_content
|
|
|
+
|
|
|
+ # ai_messages = [
|
|
|
+ # msg
|
|
|
+ # for msg in result.get("messages", [])
|
|
|
+ # if hasattr(msg, "type") and msg.type == "ai"
|
|
|
+ # ]
|
|
|
+
|
|
|
+ # if ai_messages:
|
|
|
+ # # 获取最后一条 AI 消息的内容
|
|
|
+ # last_ai_content = ai_messages[-1].content
|
|
|
+ # chat_logger.info(
|
|
|
+ # f"Worker{worker_type}执行成功:last_ai_content={last_ai_content}"
|
|
|
+ # )
|
|
|
+ # return last_ai_content
|
|
|
+ # else:
|
|
|
+ # return ""
|
|
|
|
|
|
except Exception as e:
|
|
|
chat_logger.error(
|