From e1bee481522fdc542ab70391e619009a46ca5451 Mon Sep 17 00:00:00 2001 From: zdwy5 <65889142+zdwy5@users.noreply.github.com> Date: Fri, 12 Dec 2025 17:09:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=AF=E6=8C=81aws=20=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E5=85=A8=E5=B1=80=E5=8F=82=E6=95=B0=E9=80=8F=E4=BC=A0?= =?UTF-8?q?=E6=88=96=E8=80=85=E6=B8=A0=E9=81=93=E5=8F=82=E6=95=B0=E9=80=8F?= =?UTF-8?q?=E4=BC=A0=E6=9D=A5=20=E8=B0=83=E7=94=A8=20(#2423)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 支持aws 通过全局参数透传或者渠道参数透传来 调用 * fix(aws): replace json.Unmarshal with common.Unmarshal for request body processing --------- Co-authored-by: r0 Co-authored-by: CaIon --- relay/channel/aws/relay-aws.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/relay/channel/aws/relay-aws.go b/relay/channel/aws/relay-aws.go index d2ac2f0bb..a5bc896b2 100644 --- a/relay/channel/aws/relay-aws.go +++ b/relay/channel/aws/relay-aws.go @@ -18,6 +18,7 @@ import ( "github.com/gin-gonic/gin" "github.com/pkg/errors" + "github.com/QuantumNous/new-api/setting/model_setting" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/credentials" "github.com/aws/aws-sdk-go-v2/service/bedrockruntime" @@ -129,7 +130,7 @@ func doAwsClientRequest(c *gin.Context, info *relaycommon.RelayInfo, a *Adaptor, Accept: aws.String("application/json"), ContentType: aws.String("application/json"), } - awsReq.Body, err = common.Marshal(awsClaudeReq) + awsReq.Body, err = buildAwsRequestBody(c, info, awsClaudeReq) if err != nil { return nil, types.NewError(errors.Wrap(err, "marshal aws request fail"), types.ErrorCodeBadRequestBody) } @@ -141,7 +142,7 @@ func doAwsClientRequest(c *gin.Context, info *relaycommon.RelayInfo, a *Adaptor, Accept: aws.String("application/json"), ContentType: aws.String("application/json"), } - awsReq.Body, err = common.Marshal(awsClaudeReq) + awsReq.Body, err = buildAwsRequestBody(c, info, awsClaudeReq) if err != nil { return nil, types.NewError(errors.Wrap(err, "marshal aws request fail"), types.ErrorCodeBadRequestBody) } @@ -151,6 +152,24 @@ func doAwsClientRequest(c *gin.Context, info *relaycommon.RelayInfo, a *Adaptor, } } +// buildAwsRequestBody prepares the payload for AWS requests, applying passthrough rules when enabled. +func buildAwsRequestBody(c *gin.Context, info *relaycommon.RelayInfo, awsClaudeReq any) ([]byte, error) { + if model_setting.GetGlobalSettings().PassThroughRequestEnabled || info.ChannelSetting.PassThroughBodyEnabled { + body, err := common.GetRequestBody(c) + if err != nil { + return nil, errors.Wrap(err, "get request body for pass-through fail") + } + var data map[string]interface{} + if err := common.Unmarshal(body, &data); err != nil { + return nil, errors.Wrap(err, "pass-through unmarshal request body fail") + } + delete(data, "model") + delete(data, "stream") + return common.Marshal(data) + } + return common.Marshal(awsClaudeReq) +} + func getAwsRegionPrefix(awsRegionId string) string { parts := strings.Split(awsRegionId, "-") regionPrefix := ""