Skip to content

Commit 4ec1824

Browse files
committed
server (webui): Fix issue with muliple <think> tags
1 parent 19d3c82 commit 4ec1824

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

examples/server/public/index.html.gz

7.98 KB
Binary file not shown.

examples/server/webui/src/components/ChatMessage.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@ export default function ChatMessage({
4747
let actualContent = '';
4848
let thought = '';
4949
let isThinking = false;
50-
let thinkSplit = msg.content.split('<think>', 2);
51-
actualContent += thinkSplit[0];
52-
while (thinkSplit[1] !== undefined) {
50+
let [match, ...rest] = msg.content.split('<think>');
51+
actualContent += match;
52+
while (rest.length != 0) {
5353
// <think> tag found
54-
thinkSplit = thinkSplit[1].split('</think>', 2);
55-
thought += thinkSplit[0];
54+
[match, ...rest] = rest.join('<think>').split('</think>');
55+
thought += thought !== '' ? '\n***\n' + match : match;
5656
isThinking = true;
57-
if (thinkSplit[1] !== undefined) {
57+
if (rest.length != 0) {
5858
// </think> closing tag found
5959
isThinking = false;
60-
thinkSplit = thinkSplit[1].split('<think>', 2);
61-
actualContent += thinkSplit[0];
60+
[match, ...rest] = rest.join('</think>').split('<think>');
61+
actualContent += match;
6262
}
6363
}
6464
return { content: actualContent, thought, isThinking };

0 commit comments

Comments
 (0)