Merge pull request #1496 from Yidadaa/refactor-api

fixup
This commit is contained in:
Yifei Zhang
2023-05-15 01:56:14 +08:00
committed by GitHub

View File

@@ -103,11 +103,15 @@ export class ChatGPTApi implements LLMApi {
return finish();
}
if (text.length === 0) continue;
const json = JSON.parse(text);
const delta = json.choices[0].delta.content;
if (delta) {
responseText += delta;
options.onUpdate?.(responseText, delta);
try {
const json = JSON.parse(text);
const delta = json.choices[0].delta.content;
if (delta) {
responseText += delta;
options.onUpdate?.(responseText, delta);
}
} catch (e) {
console.error("[Request] parse error", text, chunk);
}
}
}