修复AI分析结果中显示多余代码块标记的问题
This commit is contained in:
parent
1625f8d3f6
commit
d2e29d9537
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user