mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
fix(puterai): close streams
This commit is contained in:
parent
5a616f67dd
commit
eb18550f41
@ -90,6 +90,7 @@ class ClaudeService extends BaseService {
|
|||||||
});
|
});
|
||||||
stream.write(str + '\n');
|
stream.write(str + '\n');
|
||||||
}
|
}
|
||||||
|
stream.end();
|
||||||
})();
|
})();
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -54,6 +54,7 @@ class GroqAIService extends BaseService {
|
|||||||
});
|
});
|
||||||
stream.write(str + '\n');
|
stream.write(str + '\n');
|
||||||
}
|
}
|
||||||
|
stream.end();
|
||||||
})();
|
})();
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ class MistralAIService extends BaseService {
|
|||||||
});
|
});
|
||||||
stream.write(str + '\n');
|
stream.write(str + '\n');
|
||||||
}
|
}
|
||||||
|
stream.end();
|
||||||
})();
|
})();
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -232,6 +232,7 @@ class OpenAICompletionService extends BaseService {
|
|||||||
});
|
});
|
||||||
stream.write(str + '\n');
|
stream.write(str + '\n');
|
||||||
}
|
}
|
||||||
|
stream.end();
|
||||||
})();
|
})();
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,7 @@ class TogetherAIService extends BaseService {
|
|||||||
});
|
});
|
||||||
stream.write(str + '\n');
|
stream.write(str + '\n');
|
||||||
}
|
}
|
||||||
|
stream.end();
|
||||||
})();
|
})();
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -279,15 +279,12 @@ async function driverCall_(
|
|||||||
// ===============================================
|
// ===============================================
|
||||||
|
|
||||||
let is_stream = false;
|
let is_stream = false;
|
||||||
let got_headers = false;
|
|
||||||
let signal_stream_update = null;
|
let signal_stream_update = null;
|
||||||
let lastLength = 0;
|
let lastLength = 0;
|
||||||
let response_complete = false;
|
let response_complete = false;
|
||||||
const parts_received = [];
|
const parts_received = [];
|
||||||
xhr.onreadystatechange = () => {
|
xhr.onreadystatechange = () => {
|
||||||
if ( got_headers ) return;
|
if ( xhr.readyState === 2 ) {
|
||||||
got_headers = true;
|
|
||||||
if ( xhr.readyState >= 2 ) {
|
|
||||||
if ( xhr.getResponseHeader("Content-Type") !==
|
if ( xhr.getResponseHeader("Content-Type") !==
|
||||||
'application/x-ndjson'
|
'application/x-ndjson'
|
||||||
) return;
|
) return;
|
||||||
@ -311,6 +308,12 @@ async function driverCall_(
|
|||||||
|
|
||||||
return resolve_func(Stream());
|
return resolve_func(Stream());
|
||||||
}
|
}
|
||||||
|
if ( xhr.readyState === 4 ) {
|
||||||
|
response_complete = true;
|
||||||
|
if ( is_stream ) {
|
||||||
|
signal_stream_update?.();
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
xhr.onprogress = function() {
|
xhr.onprogress = function() {
|
||||||
@ -323,19 +326,13 @@ async function driverCall_(
|
|||||||
signal_stream_update();
|
signal_stream_update();
|
||||||
};
|
};
|
||||||
|
|
||||||
xhr.addEventListener('load', () => {
|
|
||||||
response_complete = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
// ========================
|
// ========================
|
||||||
// === END OF STREAMING ===
|
// === END OF STREAMING ===
|
||||||
// ========================
|
// ========================
|
||||||
|
|
||||||
// load: success or error
|
// load: success or error
|
||||||
xhr.addEventListener('load', async function(response){
|
xhr.addEventListener('load', async function(response){
|
||||||
response_complete = true;
|
|
||||||
if ( is_stream ) {
|
if ( is_stream ) {
|
||||||
signal_stream_update?.();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const resp = await parseResponse(response.target);
|
const resp = await parseResponse(response.target);
|
||||||
|
Loading…
Reference in New Issue
Block a user