Update app.js
Browse files
app.js
CHANGED
@@ -34,8 +34,6 @@ function createOpenAIChunk(content, model, finishReason = null) {
|
|
34 |
}
|
35 |
|
36 |
async function* streamNotdiamondResponse(response, model) {
|
37 |
-
const reader = response.body.getReader();
|
38 |
-
const decoder = new TextDecoder();
|
39 |
let buffer = "";
|
40 |
let lastContent = "";
|
41 |
|
@@ -43,11 +41,8 @@ async function* streamNotdiamondResponse(response, model) {
|
|
43 |
return str.replace(/\${2,}/, match => match.slice(1));
|
44 |
}
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
if (done) break;
|
49 |
-
|
50 |
-
buffer += decoder.decode(value, { stream: true });
|
51 |
let lines = buffer.split('\n');
|
52 |
buffer = lines.pop() || "";
|
53 |
|
|
|
34 |
}
|
35 |
|
36 |
async function* streamNotdiamondResponse(response, model) {
|
|
|
|
|
37 |
let buffer = "";
|
38 |
let lastContent = "";
|
39 |
|
|
|
41 |
return str.replace(/\${2,}/, match => match.slice(1));
|
42 |
}
|
43 |
|
44 |
+
for await (const chunk of response.body) {
|
45 |
+
buffer += chunk.toString();
|
|
|
|
|
|
|
46 |
let lines = buffer.split('\n');
|
47 |
buffer = lines.pop() || "";
|
48 |
|