|
@@ -25,11 +25,20 @@ export function parseOutline(jsonStr: string): OutlineData | null {
|
|
|
let data: any;
|
|
let data: any;
|
|
|
|
|
|
|
|
// 策略1:直接解析(最理想情况,LLM 直接输出纯 JSON)
|
|
// 策略1:直接解析(最理想情况,LLM 直接输出纯 JSON)
|
|
|
|
|
+ let cleanedStr = jsonStr.trim();
|
|
|
|
|
+
|
|
|
|
|
+ // 清理思考标签
|
|
|
|
|
+ cleanedStr = cleanedStr.replace(/^[\s\S]*?<\/?blockquote>[\s\S]*/gi, '');
|
|
|
|
|
+ const thinkEndIdx = cleanedStr.indexOf('</think>');
|
|
|
|
|
+ if (thinkEndIdx !== -1) {
|
|
|
|
|
+ cleanedStr = cleanedStr.substring(thinkEndIdx + 8).trim();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
- data = JSON.parse(jsonStr.trim());
|
|
|
|
|
|
|
+ data = JSON.parse(cleanedStr);
|
|
|
} catch {
|
|
} catch {
|
|
|
// 策略2:提取 JSON 对象(处理 LLM 加了 markdown 标记或多余文字)
|
|
// 策略2:提取 JSON 对象(处理 LLM 加了 markdown 标记或多余文字)
|
|
|
- const match = jsonStr.match(/\{[\s\S]*\}/);
|
|
|
|
|
|
|
+ const match = cleanedStr.match(/\{[\s\S]*\}/);
|
|
|
if (!match) {
|
|
if (!match) {
|
|
|
console.error('[OutlineParser] 未找到 JSON 对象');
|
|
console.error('[OutlineParser] 未找到 JSON 对象');
|
|
|
return null;
|
|
return null;
|