From 586c3536cae1dae8fdc2436dd1733854b734bb06 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Fri, 24 Oct 2025 11:35:27 +0800 Subject: [PATCH] feat: AI dialogue nodes support historical chat history parameters (#4245) --- .../ai_chat_step_node/impl/base_chat_node.py | 18 ++++++++++-------- .../lang/en-US/views/application-workflow.ts | 1 + .../lang/zh-CN/views/application-workflow.ts | 1 + .../lang/zh-Hant/views/application-workflow.ts | 1 + ui/src/workflow/common/data.ts | 4 ++++ ui/src/workflow/nodes/ai-chat-node/index.vue | 1 - 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py b/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py index ceb7ecc95..20dc22b25 100644 --- a/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py +++ b/apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py @@ -17,7 +17,6 @@ from django.db.models import QuerySet from langchain.schema import HumanMessage, SystemMessage from langchain_core.messages import BaseMessage, AIMessage - from application.flow.i_step_node import NodeResult, INode from application.flow.step_node.ai_chat_step_node.i_chat_node import IChatNode from application.flow.tools import Reasoning, mcp_response_generator @@ -91,7 +90,6 @@ def write_context_stream(node_variable: Dict, workflow_variable: Dict, node: INo _write_context(node_variable, workflow_variable, node, workflow, answer, reasoning_content) - def write_context(node_variable: Dict, workflow_variable: Dict, node: INode, workflow): """ 写入上下文数据 @@ -194,12 +192,16 @@ class BaseChatNode(IChatNode): if stream: r = chat_model.stream(message_list) return NodeResult({'result': r, 'chat_model': chat_model, 'message_list': message_list, - 'history_message': history_message, 'question': question.content}, {}, + 'history_message': [{'content': message.content, 'role': message.type} for message in + (history_message if history_message is not None else [])], + 'question': question.content}, {}, _write_context=write_context_stream) else: r = chat_model.invoke(message_list) return NodeResult({'result': r, 'chat_model': chat_model, 'message_list': message_list, - 'history_message': history_message, 'question': question.content}, {}, + 'history_message': [{'content': message.content, 'role': message.type} for message in + (history_message if history_message is not None else [])], + 'question': question.content}, {}, _write_context=write_context) def _handle_mcp_request(self, mcp_enable, tool_enable, mcp_source, mcp_servers, mcp_tool_id, mcp_tool_ids, tool_ids, @@ -250,7 +252,9 @@ class BaseChatNode(IChatNode): r = mcp_response_generator(chat_model, message_list, json.dumps(mcp_servers_config), mcp_output_enable) return NodeResult( {'result': r, 'chat_model': chat_model, 'message_list': message_list, - 'history_message': history_message, 'question': question.content}, {}, + 'history_message': [{'content': message.content, 'role': message.type} for message in + (history_message if history_message is not None else [])], + 'question': question.content}, {}, _write_context=write_context_stream) return None @@ -316,9 +320,7 @@ class BaseChatNode(IChatNode): "index": index, 'run_time': self.context.get('run_time'), 'system': self.context.get('system'), - 'history_message': [{'content': message.content, 'role': message.type} for message in - (self.context.get('history_message') if self.context.get( - 'history_message') is not None else [])], + 'history_message': self.context.get('history_message'), 'question': self.context.get('question'), 'answer': self.context.get('answer'), 'reasoning_content': self.context.get('reasoning_content'), diff --git a/ui/src/locales/lang/en-US/views/application-workflow.ts b/ui/src/locales/lang/en-US/views/application-workflow.ts index 849dc291f..658e71fb0 100644 --- a/ui/src/locales/lang/en-US/views/application-workflow.ts +++ b/ui/src/locales/lang/en-US/views/application-workflow.ts @@ -125,6 +125,7 @@ export default { }, defaultPrompt: 'Known Information', think: 'Thinking Process', + historyMessage: 'Historical chat records', }, searchKnowledgeNode: { label: 'Knowledge Retrieval', diff --git a/ui/src/locales/lang/zh-CN/views/application-workflow.ts b/ui/src/locales/lang/zh-CN/views/application-workflow.ts index 857ca8096..7ed00d01c 100644 --- a/ui/src/locales/lang/zh-CN/views/application-workflow.ts +++ b/ui/src/locales/lang/zh-CN/views/application-workflow.ts @@ -128,6 +128,7 @@ export default { }, defaultPrompt: '已知信息', think: '思考过程', + historyMessage: '历史聊天记录', }, searchKnowledgeNode: { label: '知识库检索', diff --git a/ui/src/locales/lang/zh-Hant/views/application-workflow.ts b/ui/src/locales/lang/zh-Hant/views/application-workflow.ts index 3d23a7b91..38083ac7e 100644 --- a/ui/src/locales/lang/zh-Hant/views/application-workflow.ts +++ b/ui/src/locales/lang/zh-Hant/views/application-workflow.ts @@ -126,6 +126,7 @@ export default { }, defaultPrompt: '已知信息', think: '思考過程', + historyMessage: '歷史聊天記錄', }, searchKnowledgeNode: { label: '知識庫檢索', diff --git a/ui/src/workflow/common/data.ts b/ui/src/workflow/common/data.ts index b6037b73b..e22e40a5a 100644 --- a/ui/src/workflow/common/data.ts +++ b/ui/src/workflow/common/data.ts @@ -82,6 +82,10 @@ export const aiChatNode = { label: t('views.applicationWorkflow.nodes.aiChatNode.think'), value: 'reasoning_content', }, + { + label: t('views.applicationWorkflow.nodes.aiChatNode.historyMessage'), + value: 'history_message', + }, ], }, }, diff --git a/ui/src/workflow/nodes/ai-chat-node/index.vue b/ui/src/workflow/nodes/ai-chat-node/index.vue index 2aea49b7e..2d1bf9d51 100644 --- a/ui/src/workflow/nodes/ai-chat-node/index.vue +++ b/ui/src/workflow/nodes/ai-chat-node/index.vue @@ -463,7 +463,6 @@ const openGeneratePromptDialog = (modelId: string) => { } } const replace = (v: any) => { - console.log(props.nodeModel.properties.node_data.model_setting) set(props.nodeModel.properties.node_data, 'system', v) } const openReasoningParamSettingDialog = () => {