Skip to content

Commit 4ec118e

Browse files
fix: prevent reasoning blocks with quotes from being truncated
1 parent 3a2bdcd commit 4ec118e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

tools/server/webui/src/lib/utils/thinking.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ export function parseThinkingContent(content: string): {
2323
};
2424
}
2525

26-
const completeMatch = content.includes('</think>');
26+
const completeMatch = content.match(/<think>([\s\S]*?)<\/think>/);
2727

2828
if (completeMatch) {
29+
const thinkingContent = completeMatch[1]?.trim() ?? '';
30+
const cleanContent = `${content.slice(0, completeMatch.index ?? 0)}${content.slice(
31+
(completeMatch.index ?? 0) + completeMatch[0].length
32+
)}`.trim();
33+
2934
return {
30-
thinking: content.split('</think>')?.[0]?.trim(),
31-
cleanContent: content.split('</think>')?.[1]?.trim()
35+
thinking: thinkingContent,
36+
cleanContent
3237
};
3338
}
3439

0 commit comments

Comments
 (0)