Spaces:
Paused
Paused
djmuted
commited on
Commit
·
f47c877
1
Parent(s):
f406747
Fix crash
Browse files- src/openai.js +1 -1
- src/utils.js +1 -0
src/openai.js
CHANGED
@@ -68,7 +68,7 @@ openaiRouter.post("/chat/completions", jsonParser, async (req, res) => {
|
|
68 |
|
69 |
let lastContent = '';
|
70 |
const onData = (newContentEncoded) => {
|
71 |
-
const newContent = decode(newContentEncoded)
|
72 |
if (stream) {
|
73 |
const data = newContent.slice(lastContent.length);
|
74 |
lastContent = newContent;
|
|
|
68 |
|
69 |
let lastContent = '';
|
70 |
const onData = (newContentEncoded) => {
|
71 |
+
const newContent = decode(newContentEncoded);
|
72 |
if (stream) {
|
73 |
const data = newContent.slice(lastContent.length);
|
74 |
lastContent = newContent;
|
src/utils.js
CHANGED
@@ -94,6 +94,7 @@ function splitJsonArray(jsonArray, maxLength) {
|
|
94 |
currentLength = addObjectToChunk(obj, currentChunk);
|
95 |
} else {
|
96 |
const lastObjectInChunk = currentChunk[currentChunk.length - 1];
|
|
|
97 |
const lastObjectWithJail = appendTextToContent(lastObjectInChunk, ` ${jail}`);
|
98 |
const lastObjectWithJailLength = JSON.stringify(lastObjectWithJail).length + 1;
|
99 |
|
|
|
94 |
currentLength = addObjectToChunk(obj, currentChunk);
|
95 |
} else {
|
96 |
const lastObjectInChunk = currentChunk[currentChunk.length - 1];
|
97 |
+
if (!lastObjectInChunk) continue;
|
98 |
const lastObjectWithJail = appendTextToContent(lastObjectInChunk, ` ${jail}`);
|
99 |
const lastObjectWithJailLength = JSON.stringify(lastObjectWithJail).length + 1;
|
100 |
|