Maybe working

This commit is contained in:
Skylar Grant 2025-01-04 11:17:25 -05:00
parent a9e8b64fc3
commit a0476cb3d0

View File

@ -21,7 +21,6 @@ async function sendGen() {
}
async function readResponse(response) {
console.log(response);
const reader = response.body.getReader();
const decoder = new TextDecoder('utf-8');
@ -32,18 +31,12 @@ async function readResponse(response) {
function read() {
// Recursive function to read the stream
reader.read().then(( chunk ) => {
console.log(`Done: ${JSON.stringify(chunk.done)}`);
console.log(`Value: ${new TextDecoder().decode(chunk.value)}`);
if (chunk.value) {
const text = decoder.decode(chunk.value);
console.log(`Text: ${text}`);
finishedResponse += text;
console.log(`(un)finishedResponse: ${finishedResponse}`);
}
if (chunk.done) {
console.log(`Finished: ${finishedResponse}`);
const lines = finishedResponse.split('\n');
console.log(lines);
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
if (line.length > 0) {
@ -57,7 +50,7 @@ async function readResponse(response) {
cleanResponse.push(JSONline.response);
}
}
console.log(cleanResponse.join(''));
outputArea.innerHTML = cleanResponse;
return;
}
read();