Fix chat parser to process messages individually

Instead of concatenating all messages into a single text block, this
change processes each message individually through the parser with
appropriate role information.
This commit is contained in:
Torsten Dittmann
2025-05-13 15:37:26 +02:00
parent f99e8d3f5e
commit cb4ad1ad9e
+9 -5
View File
@@ -35,7 +35,7 @@
chatWidth = resizerLeftPosition - resizerLeftOffset;
});
let isResizing = false;
let isResizing = $state(false);
function startResize() {
isResizing = true;
@@ -121,10 +121,14 @@
convo.data.artifactId,
convo.data.$id
);
const text = messages.reduce((curr, next) => {
return curr + next.content;
}, '');
parser.init(text);
for (const message of messages) {
const from = message.role === 'assistant' ? 'system' : 'user';
parser.chunk(message.content, from, {
silent: true
});
parser.end();
}
});
parser.on('complete', async (action) => {