From 22ce8351a161c7f20be8eb693476440fe248d0c3 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 Date: Wed, 12 Feb 2025 16:06:07 +0800 Subject: [PATCH] fix: AI dialogue context removes form data --- .../flow/step_node/ai_chat_step_node/impl/base_chat_node.py | 5 ++++- .../flow/step_node/question_node/impl/base_question_node.py | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) 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 d72d93b4fa8..7da004822fe 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 @@ -6,6 +6,7 @@ @date:2024/6/4 14:30 @desc: """ +import re import time from functools import reduce from typing import List, Dict @@ -14,7 +15,6 @@ from langchain.schema import HumanMessage, SystemMessage from langchain_core.messages import BaseMessage, AIMessage -from application.flow.common import Answer 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 @@ -181,6 +181,9 @@ def get_history_message(history_chat_record, dialogue_number, dialogue_type, run get_message(history_chat_record[index], dialogue_type, runtime_node_id) for index in range(start_index if start_index > 0 else 0, len(history_chat_record))], []) + for message in history_message: + if isinstance(message.content, str): + message.content = re.sub('[\d\D]*?<\/form_rander>', '', message.content) return history_message def generate_prompt_question(self, prompt): diff --git a/apps/application/flow/step_node/question_node/impl/base_question_node.py b/apps/application/flow/step_node/question_node/impl/base_question_node.py index d20b5a5f881..48a2639b782 100644 --- a/apps/application/flow/step_node/question_node/impl/base_question_node.py +++ b/apps/application/flow/step_node/question_node/impl/base_question_node.py @@ -6,6 +6,7 @@ @date:2024/6/4 14:30 @desc: """ +import re import time from functools import reduce from typing import List, Dict @@ -114,6 +115,9 @@ def get_history_message(history_chat_record, dialogue_number): [history_chat_record[index].get_human_message(), history_chat_record[index].get_ai_message()] for index in range(start_index if start_index > 0 else 0, len(history_chat_record))], []) + for message in history_message: + if isinstance(message.content, str): + message.content = re.sub('[\d\D]*?<\/form_rander>', '', message.content) return history_message def generate_prompt_question(self, prompt):