Skip to content

Commit

Permalink
fix: ignore empty choices
Browse files Browse the repository at this point in the history
  • Loading branch information
Nomango authored and liby committed Nov 29, 2023
1 parent 68843fc commit 1972d1a
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,20 +213,8 @@ function handleResponse(query, targetText, textFromResponse) {
try {
const dataObj = JSON.parse(textFromResponse);
const { choices } = dataObj;
if (!choices || choices.length === 0) {
query.onCompletion({
error: {
type: "api",
message: "接口未返回结果",
addtion: textFromResponse,
},
});
return targetText;
}

const content = choices[0].delta.content;
if (content !== undefined) {
targetText += content;
if (choices && choices[0] && choices[0].delta.content) {
targetText += choices[0].delta.content;
query.onStream({
result: {
from: query.detectFrom,
Expand Down

0 comments on commit 1972d1a

Please sign in to comment.