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

@@ -2,6 +2,7 @@ package controller
import (
"bufio"
"context"
"encoding/json"
"fmt"
"io"
@@ -117,7 +118,12 @@ func requestOpenAI2Gemini(textRequest GeneralOpenAIRequest) *GeminiChatRequest {
if imageNum > GeminiVisionMaxImageNum {
continue
}
mimeType, data, _ := image.GetImageFromUrl(part.ImageURL.Url)
mimeType, data, err := image.GetImageFromUrl(part.ImageURL.Url)
if err != nil {
common.LogError(context.TODO(),
fmt.Sprintf("get image from url %s got %+v", part.ImageURL.Url, err))
}
parts = append(parts, GeminiPart{
InlineData: &GeminiInlineData{
MimeType: mimeType,