Skip to content

Commit 1972d1a

Browse files
Nomangoliby
authored andcommitted
fix: ignore empty choices
1 parent 68843fc commit 1972d1a

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

src/main.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -213,20 +213,8 @@ function handleResponse(query, targetText, textFromResponse) {
213213
try {
214214
const dataObj = JSON.parse(textFromResponse);
215215
const { choices } = dataObj;
216-
if (!choices || choices.length === 0) {
217-
query.onCompletion({
218-
error: {
219-
type: "api",
220-
message: "接口未返回结果",
221-
addtion: textFromResponse,
222-
},
223-
});
224-
return targetText;
225-
}
226-
227-
const content = choices[0].delta.content;
228-
if (content !== undefined) {
229-
targetText += content;
216+
if (choices && choices[0] && choices[0].delta.content) {
217+
targetText += choices[0].delta.content;
230218
query.onStream({
231219
result: {
232220
from: query.detectFrom,

0 commit comments

Comments
 (0)