Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Fix handling of empty candidates and parts in Google text model
Browse files Browse the repository at this point in the history
  • Loading branch information
MrlolDev committed Dec 15, 2023
1 parent bbf5c76 commit 39004fe
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/models/text/google.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export default {
const cost = 0;
let resultLength = 0;
for await (const item of streamingResp.stream) {
if (item.candidates.length == 0) continue;
if (item.candidates[0]?.content?.parts.length == 0) continue;
res.result = item.candidates[0]?.content?.parts[0]?.text || "";
resultLength = item.usageMetadata?.candidates_token_count || 0;
promptLength = item.usageMetadata?.prompt_token_count || 0;
Expand All @@ -161,7 +163,15 @@ export default {
...res,
};
event.emit("data", res);
});
}).catch((err) => {
console.log(err);
console.log(request);
event.emit("data", {
done: true,

})
})

return event;
},
};

0 comments on commit 39004fe

Please # to comment.