fix: base 64 encoded format support of gemini-pro-vision for field image_url/url (#878)

This commit is contained in:
Zhanliang Liu 2024-01-01 17:00:23 +08:00 committed by GitHub
parent af8908db54
commit c725cc8842
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -44,6 +44,18 @@ func GetImageSizeFromUrl(url string) (width int, height int, err error) {
} }
func GetImageFromUrl(url string) (mimeType string, data string, err error) { func GetImageFromUrl(url string) (mimeType string, data string, err error) {
// Regex to match data URL pattern
dataURLPattern := regexp.MustCompile(`data:image/([^;]+);base64,(.*)`)
// Check if the URL is a data URL
matches := dataURLPattern.FindStringSubmatch(url)
if len(matches) == 3 {
// URL is a data URL
mimeType = "image/" + matches[1]
data = matches[2]
return
}
isImage, err := IsImageUrl(url) isImage, err := IsImageUrl(url)
if !isImage { if !isImage {
return return