From 6f9846a29041bf6f9c14b412982a277ea3cc0681 Mon Sep 17 00:00:00 2001 From: Cohee <18619528+Cohee1207@users.noreply.github.com> Date: Sun, 8 Sep 2024 02:16:54 +0300 Subject: [PATCH] #2763 Add error handler to image token cost calculation --- public/scripts/openai.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/public/scripts/openai.js b/public/scripts/openai.js index c044c9796..e0590c4ab 100644 --- a/public/scripts/openai.js +++ b/public/scripts/openai.js @@ -2455,8 +2455,13 @@ class Message { { type: 'image_url', image_url: { 'url': image, 'detail': quality } }, ]; - const tokens = await this.getImageTokenCost(image, quality); - this.tokens += tokens; + try { + 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) {