webui: don't use regex to split cot and response

This commit is contained in:
Stéphane du Hamel 2025-01-23 19:31:55 +01:00
parent 2a7d711bc5
commit 77c08a8fb8
2 changed files with 14 additions and 7 deletions

Binary file not shown.

View file

@ -190,18 +190,25 @@ const MessageBubble = defineComponent({
}; };
}, },
splitMsgContent() { splitMsgContent() {
// TODO: make it more efficient
const content = this.msg.content; const content = this.msg.content;
if (this.msg.role !== 'assistant'){ if (this.msg.role !== 'assistant'){
return {content}; return {content};
} }
const regex = /<think>(.*?)?(?=(<\/think>)|$)/gis; let actualContent = '';
const matches = []; let cot = '';
let match; let thinkSplit = content.split("<think>",2);
while ((match = regex.exec(content)) !== null) { actualContent += thinkSplit[0];
matches.push(match[1]); while (thinkSplit[1]!==undefined){
// <think> tag found
thinkSplit = thinkSplit[1].split("</think>",2);
cot+=thinkSplit[0];
if(thinkSplit[1]!==undefined){
// </think> closing tag found
thinkSplit = thinkSplit[1].split("<think>",2);
actualContent+=thinkSplit[0];
}
} }
return {content : content.replace(/<think>.*?(<\/think>|$)/gis, ''), cot : matches.join('<br/>') }; return {content : actualContent, cot };
}, },
}, },
methods: { methods: {