Skip to content

Commit

Permalink
server (webui): Fix issue with muliple <think> tags
Browse files Browse the repository at this point in the history
  • Loading branch information
stduhpf committed Feb 10, 2025
1 parent 19d3c82 commit 3ab6211
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
Binary file modified examples/server/public/index.html.gz
Binary file not shown.
16 changes: 8 additions & 8 deletions examples/server/webui/src/components/ChatMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@ export default function ChatMessage({
let actualContent = '';
let thought = '';
let isThinking = false;
let thinkSplit = msg.content.split('<think>', 2);
actualContent += thinkSplit[0];
while (thinkSplit[1] !== undefined) {
let [match, ...rest] = msg.content.split('<think>');
actualContent += match;
while (rest.length !== 0) {
// <think> tag found
thinkSplit = thinkSplit[1].split('</think>', 2);
thought += thinkSplit[0];
[match, ...rest] = rest.join('<think>').split('</think>');
thought += thought !== '' ? '\n***\n' + match : match;
isThinking = true;
if (thinkSplit[1] !== undefined) {
if (rest.length !== 0) {
// </think> closing tag found
isThinking = false;
thinkSplit = thinkSplit[1].split('<think>', 2);
actualContent += thinkSplit[0];
[match, ...rest] = rest.join('</think>').split('<think>');
actualContent += match;
}
}
return { content: actualContent, thought, isThinking };
Expand Down

0 comments on commit 3ab6211

Please sign in to comment.