🔖 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:
parent
0f658c5a53
commit
02a9087b9a
@ -111,8 +111,12 @@ func GetImageSizeFromBase64(encoded string) (width int, height int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetImageSize(image 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)
|
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)
|
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,8 @@ func CountTokenMessages(messages []types.ChatCompletionMessage, model string) in
|
|||||||
}
|
}
|
||||||
imageTokens, err := countImageTokens(url, detail)
|
imageTokens, err := countImageTokens(url, detail)
|
||||||
if err != nil {
|
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 {
|
} else {
|
||||||
tokenNum += imageTokens
|
tokenNum += imageTokens
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user