Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ def get_history_message(history_chat_record, dialogue_number, dialogue_type, run
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('<form_rander>[\d\D]*?<\/form_rander>', '', message.content)
message.content = re.sub(r'<form_rander>.*?<\/form_rander>', '', message.content, flags=re.DOTALL)
return history_message

def generate_prompt_question(self, prompt):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,14 @@ def reset_application_node_dict(application_node_dict, runtime_node_id, node_dat
application_node = application_node_dict[key]
if application_node.get('runtime_node_id') == runtime_node_id:
content: str = application_node.get('content')
match = re.search('<form_rander>.*?</form_rander>', content)
match = re.search(r'<form_rander>.*?<\/form_rander>', content, flags=re.DOTALL)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修复1

if match:
form_setting_str = match.group().replace('<form_rander>', '').replace('</form_rander>', '')
form_setting = json.loads(form_setting_str)
form_setting['is_submit'] = True
form_setting['form_data'] = node_data
value = f'<form_rander>{json.dumps(form_setting)}</form_rander>'
res = re.sub('<form_rander>.*?</form_rander>',
'${value}', content)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修复2

res = re.sub(r'<form_rander>.*?<\/form_rander>', '${value}', content, flags=re.DOTALL)
application_node['content'] = res.replace('${value}', value)
except Exception as e:
maxkb_logger.warning(f'reset_application_node_dict error: {e}', exc_info=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def get_history_message(history_chat_record, dialogue_number):

for message in history_message:
if isinstance(message.content, str):
message.content = re.sub('<form_rander>[\d\D]*?<\/form_rander>', '', message.content)
message.content = re.sub(r'<form_rander>.*?<\/form_rander>', '', message.content, flags=re.DOTALL)
return history_message

def build_system_prompt(self) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def json_loads(response, expected_fields):
extraction_strategies = [
lambda: json.loads(cleaned),
lambda: json.loads(re.search(r'```(?:json)?\s*(\{.*?\})\s*```', cleaned, re.DOTALL).group(1)),
lambda: json.loads(re.search(r'(\{[\s\S]*\})', cleaned).group(1)),
lambda: json.loads(re.search(r'(\{.*\})', cleaned, flags=re.DOTALL).group(1)),
]
for strategy in extraction_strategies:
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def get_history_message(history_chat_record, dialogue_number):
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('<form_rander>[\d\D]*?<\/form_rander>', '', message.content)
message.content = re.sub(r'<form_rander>.*?<\/form_rander>', '', message.content, flags=re.DOTALL)
return history_message

def generate_prompt_question(self, prompt):
Expand Down
2 changes: 1 addition & 1 deletion apps/application/long_term_memory/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def _run_extract(workspace_id, application_id, chat_user_id, config, history_lim
]):
content += chunk.content

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

if long_term_memory:
long_term_memory.memory = content
Expand Down
6 changes: 3 additions & 3 deletions apps/common/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,18 @@ def markdown_to_plain_text(md: str) -> str:
# 移除行内代码 `code`
text = re.sub(r'`(.*?)`', r'\1', text)
# 移除代码块 ```code```
text = re.sub(r'```[\s\S]*?```', '', text)
text = re.sub(r'```.*?```', '', text, flags=re.DOTALL)
# 移除多余的换行符
text = re.sub(r'\n{2,}', '\n', text)
# 使用正则表达式去除所有 HTML 标签
text = re.sub(r'<[^>]+>', '', text)
# 先移除特定媒体标签(优先级高于通用HTML标签移除)
text = re.sub(r'<(?:audio|video)(?:\s+[^>]*)?>[\s\S]*?(?:</(?:audio|video)>)?', '', text, flags=re.IGNORECASE)
text = re.sub(r'<(?:audio|video)(?:\s+[^>]*)?>.*?(?:</(?:audio|video)>)?', '', text, flags=re.DOTALL | re.IGNORECASE)
text = re.sub(r'<img[^>]*>', '', text) # 匹配图片标签
# 去除多余的空白字符(包括换行符、制表符等)
text = re.sub(r'\s+', ' ', text)
# 去除表单渲染
re.sub(r'<form_rander>[\s\S]*?<\/form_rander>', '', text)
text = re.sub(r'<form_rander>.*?<\/form_rander>', '', text, flags=re.DOTALL)
Copy link
Copy Markdown
Contributor Author

@wangliang181230 wangliang181230 Apr 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修复4:遗漏了 text = ,导致实际上并未去除表单渲染

# 去除首尾空格
text = text.strip()
return text
Expand Down
3 changes: 1 addition & 2 deletions apps/knowledge/task/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ def save_problem(knowledge_id, document_id, paragraph_id, problem):
# print(f"paragraph_id: {paragraph_id}")
# print(f"problem: {problem}")
problem = re.sub(r"^\d+\.\s*", "", problem)
pattern = r"<question>(.*?)</question>"
match = re.search(pattern, problem)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修复3

match = re.search(r"<question>(.*?)<\/question>", problem, flags=re.DOTALL)
problem = match.group(1) if match else None
if problem is None or len(problem) == 0:
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ function markdownToPlainText(md: string) {
// 移除行内代码 `code`
.replace(/`(.*?)`/g, '$1')
// 移除代码块 ```code```
.replace(/```[\s\S]*?```/g, '')
.replace(/```.*?```/gs, '')
// 移除video标签
.replace(/<video>[\s\S]*?<\/video>/g, '')
.replace(/<video>.*?<\/video>/gs, '')
// 移除html标签
.replace(/<[^>]+>/g, '')
// 移除多余的换行符
Expand All @@ -274,7 +274,7 @@ function markdownToPlainText(md: string) {
}

function removeFormRander(text: string) {
return text.replace(/<form_rander>[\s\S]*?<\/form_rander>/g, '').trim()
return text.replace(/<form_rander>.*?<\/form_rander>/gs, '').trim()
}
function getKey(keys: Array<number>, index: number) {
// 从后往前查找第一个小于等于index的键
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,15 @@ function markdownToPlainText(md: string) {
// 移除行内代码 `code`
.replace(/`(.*?)`/g, '$1')
// 移除代码块 ```code```
.replace(/```[\s\S]*?```/g, '')
.replace(/```.*?```/gs, '')
// 移除多余的换行符
.replace(/\n{2,}/g, '\n')
.trim()
)
}

function removeFormRander(text: string) {
return text.replace(/<form_rander>[\s\S]*?<\/form_rander>/g, '').trim()
return text.replace(/<form_rander>.*?<\/form_rander>/gs, '').trim()
}

const playAnswerText = (text: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ const prologue = computed(() => {
const temp = props.available ? props.application?.prologue : t('chat.tip.prologueMessage')
if (temp) {
const tag_list = [
/<html_rander>[\d\D]*?<\/html_rander>/g,
/<echarts_rander>[\d\D]*?<\/echarts_rander>/g,
/<quick_question>[\d\D]*?<\/quick_question>/g,
/<form_rander>[\d\D]*?<\/form_rander>/g,
/<html_rander>.*?<\/html_rander>/gs,
/<echarts_rander>.*?<\/echarts_rander>/gs,
/<quick_question>.*?<\/quick_question>/gs,
/<form_rander>.*?<\/form_rander>/gs,
]
let _temp = temp
for (const index in tag_list) {
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/markdown/IframeRender.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const iframeRef = ref<HTMLIFrameElement>()
const finalSource = computed(() => {
if (props.script_exec) return fSource.value

return fSource.value.replace(/<script[\s\S]*?>[\s\S]*?<\/script>/gi, '')
return fSource.value.replace(/<script.*?>.*?<\/script>/gsi, '')
})
function onMessage(e: MessageEvent) {
if (e.data?.instanceId !== instanceId) return
Expand Down
Loading