mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-11-13 03:43:44 +08:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user