Fix for Together
This commit is contained in:
parent
2859ae54ab
commit
759e8eed0c
|
@ -170,7 +170,20 @@ async function* parseStreamData(json) {
|
||||||
if (isNotPrimary || json.choices.length === 0) {
|
if (isNotPrimary || json.choices.length === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (typeof json.choices[0].delta === 'object') {
|
|
||||||
|
if (typeof json.choices[0].text === 'string' && json.choices[0].text.length > 0) {
|
||||||
|
for (let j = 0; j < json.choices[0].text.length; j++) {
|
||||||
|
const str = json.choices[0].text[j];
|
||||||
|
const choiceClone = structuredClone(json.choices[0]);
|
||||||
|
choiceClone.text = str;
|
||||||
|
const choices = [choiceClone];
|
||||||
|
yield {
|
||||||
|
data: { ...json, choices },
|
||||||
|
chunk: str,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (typeof json.choices[0].delta === 'object') {
|
||||||
if (typeof json.choices[0].delta.text === 'string' && json.choices[0].delta.text.length > 0) {
|
if (typeof json.choices[0].delta.text === 'string' && json.choices[0].delta.text.length > 0) {
|
||||||
for (let j = 0; j < json.choices[0].delta.text.length; j++) {
|
for (let j = 0; j < json.choices[0].delta.text.length; j++) {
|
||||||
const str = json.choices[0].delta.text[j];
|
const str = json.choices[0].delta.text[j];
|
||||||
|
@ -182,7 +195,8 @@ async function* parseStreamData(json) {
|
||||||
chunk: str,
|
chunk: str,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else if (typeof json.choices[0].delta.content === 'string' && json.choices[0].delta.content.length > 0) {
|
}
|
||||||
|
else if (typeof json.choices[0].delta.content === 'string' && json.choices[0].delta.content.length > 0) {
|
||||||
for (let j = 0; j < json.choices[0].delta.content.length; j++) {
|
for (let j = 0; j < json.choices[0].delta.content.length; j++) {
|
||||||
const str = json.choices[0].delta.content[j];
|
const str = json.choices[0].delta.content[j];
|
||||||
const choiceClone = structuredClone(json.choices[0]);
|
const choiceClone = structuredClone(json.choices[0]);
|
||||||
|
@ -209,18 +223,6 @@ async function* parseStreamData(json) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (typeof json.choices[0].text === 'string' && json.choices[0].text.length > 0) {
|
|
||||||
for (let j = 0; j < json.choices[0].text.length; j++) {
|
|
||||||
const str = json.choices[0].text[j];
|
|
||||||
const choiceClone = structuredClone(json.choices[0]);
|
|
||||||
choiceClone.text = str;
|
|
||||||
const choices = [choiceClone];
|
|
||||||
yield {
|
|
||||||
data: { ...json, choices },
|
|
||||||
chunk: str,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in New Issue