From c6a2d3c2fbf32bdf26cbf911daeb6f86c77c9369 Mon Sep 17 00:00:00 2001 From: liuzl Date: Thu, 28 Dec 2023 10:23:00 +0800 Subject: [PATCH] fix: base 64 encoded format support of gemini-pro-vision for field image_url/url --- common/image/image.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/common/image/image.go b/common/image/image.go index a602936a..27045d28 100644 --- a/common/image/image.go +++ b/common/image/image.go @@ -44,6 +44,18 @@ func GetImageSizeFromUrl(url string) (width int, height int, 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) if !isImage { return