#2763 Add error handler to image token cost calculation

This commit is contained in:
Cohee 2024-09-08 02:16:54 +03:00
parent 37b3184cda
commit 6f9846a290

View File

@ -2455,8 +2455,13 @@ class Message {
{ type: 'image_url', image_url: { 'url': image, 'detail': quality } }, { type: 'image_url', image_url: { 'url': image, 'detail': quality } },
]; ];
const tokens = await this.getImageTokenCost(image, quality); try {
this.tokens += tokens; const tokens = await this.getImageTokenCost(image, quality);
this.tokens += tokens;
} catch (error) {
this.tokens += Message.tokensPerImage;
console.error('Failed to get image token cost', error);
}
} }
async getImageTokenCost(dataUrl, quality) { async getImageTokenCost(dataUrl, quality) {