Created
July 5, 2024 06:14
-
-
Save elijahbenizzy/0a650adf2aca305a43b6fbefeb910ab8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while (true) { | |
const result = await reader.read(); | |
if (result.done) { | |
break; | |
} | |
const message = decoder.decode(result.value, { stream: true }); | |
message | |
.split('data: ') | |
.slice(1) | |
.forEach((item) => { | |
const event: Event = JSON.parse(item); | |
if (event.type === 'chat_history') { | |
const chatMessageEvent = event as ChatHistoryEvent; | |
setDisplayedChatHistory(chatMessageEvent.value); | |
} | |
if (event.type === 'delta') { | |
const chatMessageEvent = event as ChatMessageEvent; | |
chatResponse += chatMessageEvent.value; | |
setCurrentResponse(chatResponse); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment