fix(gateway): 过滤 Gemini 请求中 parts 为空的消息
Gemini API 不接受 contents 数组中 parts 为空的消息,会返回 400 INVALID_ARGUMENT 错误。 添加 filterEmptyPartsFromGeminiRequest 函数在转发前过滤这类消息。 影响范围:ForwardGemini (antigravity) 和 ForwardNative (gemini)
This commit is contained in:
@@ -840,6 +840,11 @@ func (s *GeminiMessagesCompatService) ForwardNative(ctx context.Context, c *gin.
|
||||
return nil, s.writeGoogleError(c, http.StatusBadRequest, "Request body is empty")
|
||||
}
|
||||
|
||||
// 过滤掉 parts 为空的消息(Gemini API 不接受空 parts)
|
||||
if filteredBody, err := filterEmptyPartsFromGeminiRequest(body); err == nil {
|
||||
body = filteredBody
|
||||
}
|
||||
|
||||
switch action {
|
||||
case "generateContent", "streamGenerateContent", "countTokens":
|
||||
// ok
|
||||
|
||||
Reference in New Issue
Block a user