This commit is contained in:
Skylar Grant 2025-01-04 10:54:28 -05:00
parent e2d12044fd
commit 9c89eeb22f

View File

@ -28,6 +28,8 @@ async function readResponse(response) {
try {
function read() {
let finishedResponse = '';
let JSONResponse = new Array();
let cleanResponse = new Array();
// Recursive function to read the stream
reader.read().then(( chunk ) => {
console.log(`Done: ${JSON.stringify(chunk.done)}`);
@ -37,8 +39,20 @@ async function readResponse(response) {
finishedResponse += text;
}
if (chunk.done) {
const responseJSON = JSON.parse(finishedResponse);
console.log(responseJSON);
const lines = finishedResponse.split('\n');
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (line.length > 0) {
const JSONline = JSON.parse(line);
JSONResponse.push(JSONline);
}
}
for (let i = 0; i < JSONResponse.length; i++) {
const JSONline = JSONResponse[i];
if (JSONline.text) {
cleanResponse.push(JSONline.response);
}
}
return;
}
read();