|
|
@@ -17,7 +17,7 @@ import (
|
|
|
)
|
|
|
|
|
|
// Setting safety to the lowest possible values since Gemini is already powerless enough
|
|
|
-func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatRequest {
|
|
|
+func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) (*GeminiChatRequest, error) {
|
|
|
geminiRequest := GeminiChatRequest{
|
|
|
Contents: make([]GeminiChatContent, 0, len(textRequest.Messages)),
|
|
|
SafetySettings: []GeminiChatSafetySettings{
|
|
|
@@ -110,7 +110,7 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
|
|
|
imageNum += 1
|
|
|
|
|
|
if constant.GeminiVisionMaxImageNum != -1 && imageNum > constant.GeminiVisionMaxImageNum {
|
|
|
- continue
|
|
|
+ return nil, fmt.Errorf("too many images in the message, max allowed is %d", constant.GeminiVisionMaxImageNum)
|
|
|
}
|
|
|
// 判断是否是url
|
|
|
if strings.HasPrefix(part.ImageUrl.(dto.MessageImageUrl).Url, "http") {
|
|
|
@@ -125,7 +125,7 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
|
|
|
} else {
|
|
|
_, format, base64String, err := service.DecodeBase64ImageData(part.ImageUrl.(dto.MessageImageUrl).Url)
|
|
|
if err != nil {
|
|
|
- continue
|
|
|
+ return nil, fmt.Errorf("decode base64 image data failed: %s", err.Error())
|
|
|
}
|
|
|
parts = append(parts, GeminiPart{
|
|
|
InlineData: &GeminiInlineData{
|
|
|
@@ -162,7 +162,7 @@ func CovertGemini2OpenAI(textRequest dto.GeneralOpenAIRequest) *GeminiChatReques
|
|
|
// shouldAddDummyModelMessage = false
|
|
|
//}
|
|
|
}
|
|
|
- return &geminiRequest
|
|
|
+ return &geminiRequest, nil
|
|
|
}
|
|
|
|
|
|
func (g *GeminiChatResponse) GetResponseText() string {
|