Skip to content

Commit 7a13e96

Browse files
committed
refactor(DifyChatflowSSETool): 简化事件流输出逻辑
移除冗余的key_events和key_events_count变量输出 使用chatflow_answer作为默认文本摘要内容
1 parent fdfa93d commit 7a13e96

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

tools/dify_chatflow_sse.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -763,29 +763,28 @@ def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessag
763763
final_result = {
764764
"status": "completed",
765765
"total_events": event_count,
766-
"key_events_count": len(key_events),
767766
"connection_duration": round(duration, 2),
768767
"chatflow_answer": chatflow_answer,
769768
"summary": f"Chatflow SSE连接成功,接收到{event_count}个事件({len(key_events)}个关键事件),耗时{duration:.2f}秒"
770769
}
771770

772-
# 构建文本摘要
773-
text_summary = f"[最终结果] 构建完成,包含{len(all_events)}个事件,{len(key_events)}个关键事件"
771+
# 构建文本摘要 - 使用chatflow_answer作为文本输出
772+
text_summary = chatflow_answer if chatflow_answer else f"[最终结果] 构建完成,包含{len(all_events)}个事件,{len(key_events)}个关键事件"
774773

775774
logger.debug(f"[最终结果] 构建完成,包含{len(all_events)}个事件,{len(key_events)}个关键事件")
776775

777776
# 返回JSON结果
778777
yield self.create_json_message(final_result)
779778

780-
# 返回文本摘要
779+
# 返回文本摘要 - 现在使用chatflow_answer的内容
781780
yield self.create_text_message(text_summary)
782781

783782
# 返回自定义变量 - 事件流数组(如果没有关键事件则返回全部事件,否则返回关键事件)
784783
events_to_stream = key_events if len(key_events) > 0 else all_events
785784
yield self.create_variable_message("events_stream", events_to_stream)
786785

787-
# 返回自定义变量 - 关键事件流数组(Chatflow专用)
788-
yield self.create_variable_message("key_events", key_events)
786+
# 移除key_events变量输出 - 根据用户要求,这个变量是多余的
787+
# yield self.create_variable_message("key_events", key_events)
789788

790789
# 返回自定义变量 - Chatflow答案(Chatflow专用)
791790
yield self.create_variable_message("chatflow_answer", chatflow_answer)
@@ -796,8 +795,8 @@ def _invoke(self, tool_parameters: dict[str, Any]) -> Generator[ToolInvokeMessag
796795
# 返回自定义变量 - 事件总数
797796
yield self.create_variable_message("total_events", event_count)
798797

799-
# 返回自定义变量 - 关键事件总数
800-
yield self.create_variable_message("key_events_count", len(key_events))
798+
# 移除key_events_count变量输出 - 因为key_events已经被移除,这个计数也不需要了
799+
# yield self.create_variable_message("key_events_count", len(key_events))
801800

802801
# 返回自定义变量 - 连接时长
803802
yield self.create_variable_message("connection_duration", round(duration, 2))

tools/dify_chatflow_sse.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,6 @@ output_schema:
237237
connection_duration:
238238
type: number
239239
description: "Connection duration in seconds"
240-
summary:
241-
type: string
242-
description: "Human readable summary of the Dify Chatflow SSE session"
243240
error:
244241
type: string
245242
description: "Error message if connection failed"

0 commit comments

Comments
 (0)