mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-03 06:12:53 +02:00
wip
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user