diff --git a/relay/channel/vertex/adaptor.go b/relay/channel/vertex/adaptor.go index c47eeccc1..481524e49 100644 --- a/relay/channel/vertex/adaptor.go +++ b/relay/channel/vertex/adaptor.go @@ -51,10 +51,43 @@ type Adaptor struct { } func (a *Adaptor) ConvertGeminiRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.GeminiChatRequest) (any, error) { + // Vertex AI does not support functionResponse.id; keep it stripped here for consistency. + if model_setting.GetGeminiSettings().RemoveFunctionResponseIdEnabled { + removeFunctionResponseID(request) + } geminiAdaptor := gemini.Adaptor{} return geminiAdaptor.ConvertGeminiRequest(c, info, request) } +func removeFunctionResponseID(request *dto.GeminiChatRequest) { + if request == nil { + return + } + + if len(request.Contents) > 0 { + for i := range request.Contents { + if len(request.Contents[i].Parts) == 0 { + continue + } + for j := range request.Contents[i].Parts { + part := &request.Contents[i].Parts[j] + if part.FunctionResponse == nil { + continue + } + if len(part.FunctionResponse.ID) > 0 { + part.FunctionResponse.ID = nil + } + } + } + } + + if len(request.Requests) > 0 { + for i := range request.Requests { + removeFunctionResponseID(&request.Requests[i]) + } + } +} + func (a *Adaptor) ConvertClaudeRequest(c *gin.Context, info *relaycommon.RelayInfo, request *dto.ClaudeRequest) (any, error) { if v, ok := claudeModelMap[info.UpstreamModelName]; ok { c.Set("request_model", v) diff --git a/relay/gemini_handler.go b/relay/gemini_handler.go index 6041b765a..af13341bf 100644 --- a/relay/gemini_handler.go +++ b/relay/gemini_handler.go @@ -162,11 +162,6 @@ func GeminiHelper(c *gin.Context, info *relaycommon.RelayInfo) (newAPIError *typ } } - // remove disabled fields for Vertex AI - if info.ChannelType == constant.ChannelTypeVertexAi { - jsonData, _ = relaycommon.RemoveGeminiDisabledFields(jsonData) - } - logger.LogDebug(c, "Gemini request body: "+string(jsonData)) requestBody = bytes.NewReader(jsonData)