trying to get the missing chunk part
This commit is contained in:
parent
59b3bd5019
commit
2d02bc1bb8
1 changed files with 18 additions and 9 deletions
|
|
@ -106,6 +106,7 @@ self.onmessage = async function(event) {
|
||||||
|
|
||||||
const reader = response.body.getReader();
|
const reader = response.body.getReader();
|
||||||
const decoder = new TextDecoder("utf-8");
|
const decoder = new TextDecoder("utf-8");
|
||||||
|
let chunk = '';
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (stopStreaming) {
|
if (stopStreaming) {
|
||||||
|
|
@ -124,16 +125,24 @@ self.onmessage = async function(event) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// lots of low-level OpenAI response parsing stuff
|
// lots of low-level OpenAI response parsing stuff
|
||||||
const chunk = decoder.decode(value);
|
chunk += decoder.decode(value);
|
||||||
|
console.log(">>>>>>>>>>>>>> [ThunderAI] chunk: " + JSON.stringify(chunk));
|
||||||
const lines = chunk.split("\n");
|
const lines = chunk.split("\n");
|
||||||
const parsedLines = lines
|
let parsedLines = [];
|
||||||
.map((line) => line.replace(/^data: /, "").trim()) // Remove the "data: " prefix
|
try{
|
||||||
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
|
parsedLines = lines
|
||||||
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
.map((line) => line.replace(/^data: /, "").trim()) // Remove the "data: " prefix
|
||||||
.map((line) => {
|
.filter((line) => line !== "" && line !== "[DONE]") // Remove empty lines and "[DONE]"
|
||||||
console.log(">>>>>>>>>>>>> [ThunderAI] line: " + JSON.stringify(line));
|
// .map((line) => JSON.parse(line)); // Parse the JSON string
|
||||||
return JSON.parse(line);
|
.map((line) => {
|
||||||
});
|
console.log(">>>>>>>>>>>>> [ThunderAI] line: " + JSON.stringify(line));
|
||||||
|
return JSON.parse(line);
|
||||||
|
});
|
||||||
|
chunk = chunk.substring(chunk.lastIndexOf('\n') + 1);
|
||||||
|
console.log(">>>>>>>>>>>>>> [ThunderAI] last chunk: " + JSON.stringify(chunk));
|
||||||
|
}catch(e){
|
||||||
|
console.error(">>>>>>>>>>>>> [ThunderAI] error: " + JSON.stringify(e));
|
||||||
|
}
|
||||||
|
|
||||||
for (const parsedLine of parsedLines) {
|
for (const parsedLine of parsedLines) {
|
||||||
const { choices } = parsedLine;
|
const { choices } = parsedLine;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue