fix: Add image support to Gemini relay

- Add support for getting base64-encoded images via openAI's image_url.
- Add `context` as a parameter for the function `LogError`.
- Handle the error from `image.GetImageFromUrl` by logging it.
- Convert the role to `user` if it is `system` and add a dummy model message to make Gemini happy.
This commit is contained in:
Laisky.Cai
2023-12-27 03:13:11 +00:00
parent 75cbfd7bb6
commit 671fe78e44
3 changed files with 17 additions and 3 deletions

View File

@@ -44,6 +44,11 @@ func GetImageSizeFromUrl(url string) (width int, height int, err error) {
}
func GetImageFromUrl(url string) (mimeType string, data string, err error) {
// openai's image_url support base64 encoded image
if strings.HasPrefix(url, "data:image/jpeg;base64,") {
return "image/jpeg", strings.TrimPrefix(url, "data:image/jpeg;base64,"), nil
}
isImage, err := IsImageUrl(url)
if !isImage {
return