Skip to content

Commit 8323676

Browse files
committed
fix: update regex for <form_rander> and <think> tags to use non-greedy matching
1 parent 237866e commit 8323676

11 files changed

Lines changed: 14 additions & 14 deletions

File tree

apps/application/flow/step_node/ai_chat_step_node/impl/base_chat_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ def get_history_message(history_chat_record, dialogue_number, dialogue_type, run
480480
)
481481
for message in history_message:
482482
if isinstance(message.content, str):
483-
message.content = re.sub(r"<form_rander>.*?<\/form_rander>", "", message.content, flags=re.DOTALL)
483+
message.content = re.sub(r"<form_rander>.*?</form_rander>", "", message.content, flags=re.DOTALL)
484484
return history_message
485485

486486
def generate_prompt_question(self, prompt, model):

apps/application/flow/step_node/application_node/impl/base_application_node.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ def reset_application_node_dict(application_node_dict, runtime_node_id, node_dat
132132
application_node = application_node_dict[key]
133133
if application_node.get('runtime_node_id') == runtime_node_id:
134134
content: str = application_node.get('content')
135-
match = re.search(r'<form_rander>.*?<\/form_rander>', content, flags=re.DOTALL)
135+
match = re.search(r'<form_rander>.*?</form_rander>', content, flags=re.DOTALL)
136136
if match:
137137
form_setting_str = match.group().replace('<form_rander>', '').replace('</form_rander>', '')
138138
form_setting = json.loads(form_setting_str)
139139
form_setting['is_submit'] = True
140140
form_setting['form_data'] = node_data
141141
value = f'<form_rander>{json.dumps(form_setting)}</form_rander>'
142-
res = re.sub(r'<form_rander>.*?<\/form_rander>', '${value}', content, flags=re.DOTALL)
142+
res = re.sub(r'<form_rander>.*?</form_rander>', '${value}', content, flags=re.DOTALL)
143143
application_node['content'] = res.replace('${value}', value)
144144
except Exception as e:
145145
maxkb_logger.warning(f'reset_application_node_dict error: {e}', exc_info=True)

apps/application/flow/step_node/intent_node/impl/base_intent_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def get_history_message(history_chat_record, dialogue_number):
134134

135135
for message in history_message:
136136
if isinstance(message.content, str):
137-
message.content = re.sub(r'<form_rander>.*?<\/form_rander>', '', message.content, flags=re.DOTALL)
137+
message.content = re.sub(r'<form_rander>.*?</form_rander>', '', message.content, flags=re.DOTALL)
138138
return history_message
139139

140140
def build_system_prompt(self) -> str:

apps/application/flow/step_node/question_node/impl/base_question_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def get_history_message(history_chat_record, dialogue_number):
131131
range(start_index if start_index > 0 else 0, len(history_chat_record))], [])
132132
for message in history_message:
133133
if isinstance(message.content, str):
134-
message.content = re.sub(r'<form_rander>.*?<\/form_rander>', '', message.content, flags=re.DOTALL)
134+
message.content = re.sub(r'<form_rander>.*?</form_rander>', '', message.content, flags=re.DOTALL)
135135
return history_message
136136

137137
def generate_prompt_question(self, prompt):

apps/application/long_term_memory/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def _run_extract(workspace_id, application_id, chat_user_id, config, history_lim
270270
]):
271271
content += chunk.content
272272

273-
content = re.sub(r'<think>.*?<\/think>', '', content, flags=re.DOTALL).strip()
273+
content = re.sub(r'<think>.*?</think>', '', content, flags=re.DOTALL).strip()
274274

275275
if long_term_memory:
276276
long_term_memory.memory = content

apps/application/workflow/nodes/ai_chat_node/ai_chat_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def _get_history_message(history_chat_record, dialogue_number, dialogue_type, ru
105105
)
106106
for message in history_message:
107107
if isinstance(message.content, str):
108-
message.content = re.sub(r"<form_rander>.*?<\/form_rander>", "", message.content, flags=re.DOTALL)
108+
message.content = re.sub(r"<form_rander>.*?</form_rander>", "", message.content, flags=re.DOTALL)
109109
return history_message
110110

111111

apps/application/workflow/nodes/intent_node/intent_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def _get_history_message(self, history_chat_record, dialogue_number):
135135

136136
for message in history_message:
137137
if isinstance(message.content, str):
138-
message.content = re.sub(r'<form_rander>.*?<\/form_rander>', '', message.content, flags=re.DOTALL)
138+
message.content = re.sub(r'<form_rander>.*?</form_rander>', '', message.content, flags=re.DOTALL)
139139
return history_message
140140

141141
def _build_system_prompt(self) -> str:

apps/application/workflow/nodes/question_node/question_node.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _get_history_message(history_chat_record, dialogue_number):
4747
for index in range(start_index if start_index > 0 else 0, len(history_chat_record))], [])
4848
for message in history_message:
4949
if isinstance(message.content, str):
50-
message.content = re.sub(r'<form_rander>.*?<\/form_rander>', '', message.content, flags=re.DOTALL)
50+
message.content = re.sub(r'<form_rander>.*?</form_rander>', '', message.content, flags=re.DOTALL)
5151
return history_message
5252

5353

apps/common/utils/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def markdown_to_plain_text(md: str) -> str:
187187
# 去除多余的空白字符(包括换行符、制表符等)
188188
text = re.sub(r"\s+", " ", text)
189189
# 去除表单渲染
190-
text = re.sub(r"<form_rander>.*?<\/form_rander>", "", text, flags=re.DOTALL)
190+
text = re.sub(r"<form_rander>.*?</form_rander>", "", text, flags=re.DOTALL)
191191
# 去除首尾空格
192192
text = text.strip()
193193
return text
@@ -438,7 +438,7 @@ def flat_map(array: List[List]):
438438

439439

440440
def parse_image(content: str):
441-
matches = re.finditer(r"!\[.*?\]\(\.\/oss\/(image|file)\/.*?\)", content)
441+
matches = re.finditer(r"!\[.*?\]\(\./oss/(image|file)/.*?\)", content)
442442
image_list = [match.group() for match in matches]
443443
return image_list
444444

@@ -447,7 +447,7 @@ def parse_file_link(content: str):
447447
"""Return non-image markdown links and HTML src refs pointing to ./oss/file/ paths."""
448448
results = []
449449
# Regular markdown links (not images): [text](./oss/file/...)
450-
for m in re.finditer(r"(?<!!)\[.*?\]\(\.\/oss\/(?:image|file)\/[^)]+\)", content):
450+
for m in re.finditer(r"(?<!!)\[.*?\]\(\./oss/(?:image|file)/[^)]+\)", content):
451451
results.append(m.group())
452452
# HTML tags with src pointing to oss paths, e.g. <video src="./oss/file/...">
453453
for m in re.finditer(r'<\w+[^>]+\bsrc=["\'](\./oss/(?:image|file)/[^"\']+)["\']', content):

apps/knowledge/serializers/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def write_image(zip_path: str, image_list: List[str]):
187187
paren_match = re.search(r'\(\./oss/(?:file|image)/([^)]+)\)', image)
188188
if src_match:
189189
oss_path = src_match.group(1)
190-
image_id = re.sub(r'^\.\/oss\/(file|image)\/', '', oss_path).strip().split(" ")[0]
190+
image_id = re.sub(r"^\./oss/(file|image)/", "", oss_path).strip().split(" ")[0]
191191
elif paren_match:
192192
image_id = paren_match.group(1).strip().split(" ")[0]
193193
else:

0 commit comments

Comments
 (0)