🔖 chore: Added File Type Check for Image Size Retrieval

* optimized the log content of uploaded files is too large

* optimized the log content of uploaded files is too large

* optimize GetImageSize
This commit is contained in:
Clivia 2024-05-27 14:25:33 +08:00 committed by GitHub
parent 0f658c5a53
commit 02a9087b9a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 3 deletions

View File

@ -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)
}

View File

@ -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
}