From 9c89eeb22f355fefff4b2b9b40cb480e600b354b Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Sat, 4 Jan 2025 10:54:28 -0500 Subject: [PATCH] ? --- src/assets/js/main.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/assets/js/main.js b/src/assets/js/main.js index 515f874..6f0bc97 100644 --- a/src/assets/js/main.js +++ b/src/assets/js/main.js @@ -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();