修复AI分析结果中显示多余代码块标记的问题

This commit is contained in:
xiao12feng 2025-11-20 11:51:30 +08:00
parent 1625f8d3f6
commit d2e29d9537

View File

@ -346,7 +346,7 @@ export default {
'1. 提取报告的核心信息和关键指标;',
'2. 分析测评结果的含义和可能的影响;',
'3. 提供专业、客观、易懂的分析解读500-800字',
'4. 使用结构化的格式输出,包含:核心结论、详细分析、建议部分;',
'4. 使用结构化的格式输出,包含:核心结论、详细分析、建议、总体结论四个部分;',
'5. 仅输出分析结果,不添加额外建议、问候语或思考过程;',
'6. 使用HTML格式输出使用<h3>标签作为小标题,<p>标签作为段落。'
].join('\n');
@ -380,6 +380,10 @@ export default {
.replace(/<think>[\s\S]*?<\/redacted_reasoning>/gi, '')
.replace(/<think[\s\S]*?>/gi, '')
.replace(/<redacted_reasoning[\s\S]*?>/gi, '')
// Markdown
.replace(/```html\s*/gi, '')
.replace(/```\s*/g, '')
.replace(/```[a-z]*\s*/gi, '')
.trim();
if (!rawResponse || rawResponse === '无法解析模型输出') {
@ -407,13 +411,19 @@ export default {
},
/** 格式化AI分析结果 */
formatAIResult(text) {
// HTML
if (text.includes('<h3>') || text.includes('<p>')) {
return text;
}
// Markdown```html```
let html = text
.replace(/```html\s*/gi, '')
.replace(/```\s*/g, '')
.replace(/```[a-z]*\s*/gi, '')
.trim();
// HTML
let html = text;
// HTML
if (html.includes('<h3>') || html.includes('<p>') || html.includes('<div>')) {
//
html = html.replace(/```html\s*/gi, '').replace(/```\s*/g, '');
return html;
}
// """"""
html = html.replace(/^(\d+[\.、]?\s*[^\n]+)$/gm, '<h3>$1</h3>');
@ -433,6 +443,9 @@ export default {
return match;
});
//
html = html.replace(/```html\s*/gi, '').replace(/```\s*/g, '');
return html;
}
}