From 02a9087b9a568c7b73a5c5db7a3db4373b627e68 Mon Sep 17 00:00:00 2001 From: Clivia <132346501+Yanyutin753@users.noreply.github.com> Date: Mon, 27 May 2024 14:25:33 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=96=20chore:=20Added=20File=20Type=20C?= =?UTF-8?q?heck=20for=20Image=20Size=20Retrieval?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ⭐optimized the log content of uploaded files is too large * optimized the log content of uploaded files is too large * optimize GetImageSize --- common/image/image.go | 8 ++++++-- common/token.go | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/common/image/image.go b/common/image/image.go index aff8cb31..92176c2f 100644 --- a/common/image/image.go +++ b/common/image/image.go @@ -111,8 +111,12 @@ func GetImageSizeFromBase64(encoded string) (width int, height int, err error) { } func GetImageSize(image string) (width int, height int, err error) { - if strings.HasPrefix(image, "data:image/") { + switch { + case strings.HasPrefix(image, "data:image/"): return GetImageSizeFromBase64(image) + case strings.HasPrefix(image, "http"): + return GetImageSizeFromUrl(image) + default: + return 0, 0, errors.New("invalid file type, Please view request interface!") } - return GetImageSizeFromUrl(image) } diff --git a/common/token.go b/common/token.go index 77ba8443..ec30f47e 100644 --- a/common/token.go +++ b/common/token.go @@ -118,7 +118,8 @@ func CountTokenMessages(messages []types.ChatCompletionMessage, model string) in } imageTokens, err := countImageTokens(url, detail) if err != nil { - SysError("error counting image tokens: " + err.Error()) + //Due to the excessive length of the error information, only extract and record the most critical part. + SysError("error counting image tokens: " + err.Error()) } else { tokenNum += imageTokens }