1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-09-03 06:12:53 +02:00
This commit is contained in:
Arik Chakma
2025-06-05 14:23:22 +06:00
parent c3160bdf3c
commit cfb06adc6a

View File

@@ -28,8 +28,22 @@ export async function readChatStream(
if (text.startsWith(CHAT_RESPONSE_PREFIX.message)) {
const textWithoutPrefix = text.replace(CHAT_RESPONSE_PREFIX.message, '');
result += textWithoutPrefix;
// basically we need to split the text by new line
// and send it to the onMessage callback
// so that we don't have broken tags for our rendering
let start = 0;
for (let i = 0; i < textWithoutPrefix.length; i++) {
if (textWithoutPrefix[i] === '\n') {
result += textWithoutPrefix.slice(start, i + 1);
await onMessage?.(result);
start = i + 1;
}
}
if (start < textWithoutPrefix.length) {
result += textWithoutPrefix.slice(start);
}
} else if (text.startsWith(CHAT_RESPONSE_PREFIX.details)) {
const textWithoutPrefix = text.replace(CHAT_RESPONSE_PREFIX.details, '');
await onDetails?.(textWithoutPrefix);