mirror of
https://github.com/QuantumNous/new-api.git
synced 2026-03-30 02:25:00 +00:00
fix: 模型设置增加针对Vertex渠道过滤content[].part[].functionResponse.id的选项,默认启用
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/QuantumNous/new-api/constant"
|
||||
"github.com/QuantumNous/new-api/dto"
|
||||
relayconstant "github.com/QuantumNous/new-api/relay/constant"
|
||||
"github.com/QuantumNous/new-api/setting/model_setting"
|
||||
"github.com/QuantumNous/new-api/types"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -634,3 +635,47 @@ func RemoveDisabledFields(jsonData []byte, channelOtherSettings dto.ChannelOther
|
||||
}
|
||||
return jsonDataAfter, nil
|
||||
}
|
||||
|
||||
// RemoveGeminiDisabledFields removes disabled fields from Gemini request JSON data
|
||||
// Currently supports removing functionResponse.id field which Vertex AI does not support
|
||||
func RemoveGeminiDisabledFields(jsonData []byte) ([]byte, error) {
|
||||
if !model_setting.GetGeminiSettings().RemoveFunctionResponseIdEnabled {
|
||||
return jsonData, nil
|
||||
}
|
||||
|
||||
var data map[string]interface{}
|
||||
if err := common.Unmarshal(jsonData, &data); err != nil {
|
||||
common.SysError("RemoveGeminiDisabledFields Unmarshal error: " + err.Error())
|
||||
return jsonData, nil
|
||||
}
|
||||
|
||||
// Process contents array
|
||||
// Handle both camelCase (functionResponse) and snake_case (function_response)
|
||||
if contents, ok := data["contents"].([]interface{}); ok {
|
||||
for _, content := range contents {
|
||||
if contentMap, ok := content.(map[string]interface{}); ok {
|
||||
if parts, ok := contentMap["parts"].([]interface{}); ok {
|
||||
for _, part := range parts {
|
||||
if partMap, ok := part.(map[string]interface{}); ok {
|
||||
// Check functionResponse (camelCase)
|
||||
if funcResp, ok := partMap["functionResponse"].(map[string]interface{}); ok {
|
||||
delete(funcResp, "id")
|
||||
}
|
||||
// Check function_response (snake_case)
|
||||
if funcResp, ok := partMap["function_response"].(map[string]interface{}); ok {
|
||||
delete(funcResp, "id")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jsonDataAfter, err := common.Marshal(data)
|
||||
if err != nil {
|
||||
common.SysError("RemoveGeminiDisabledFields Marshal error: " + err.Error())
|
||||
return jsonData, nil
|
||||
}
|
||||
return jsonDataAfter, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user