diff --git a/relay/channel/openai/adaptor.go b/relay/channel/openai/adaptor.go index def08502..a0d7ccc9 100644 --- a/relay/channel/openai/adaptor.go +++ b/relay/channel/openai/adaptor.go @@ -102,7 +102,7 @@ func (a *Adaptor) ConvertRequest(c *gin.Context, info *relaycommon.RelayInfo, re if request == nil { return nil, errors.New("request is nil") } - if info.ChannelType != common.ChannelTypeOpenAI { + if info.ChannelType != common.ChannelTypeOpenAI && info.ChannelType != common.ChannelTypeAzure { request.StreamOptions = nil } if strings.HasPrefix(request.Model, "o1-") { diff --git a/relay/relay-text.go b/relay/relay-text.go index 061a5e2c..b050ac51 100644 --- a/relay/relay-text.go +++ b/relay/relay-text.go @@ -6,6 +6,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/bytedance/sonic" "io" "math" "net/http" @@ -76,7 +77,7 @@ func TextHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) { } // map model name - isModelMapped := false + //isModelMapped := false modelMapping := c.GetString("model_mapping") //isModelMapped := false if modelMapping != "" && modelMapping != "{}" { @@ -86,7 +87,7 @@ func TextHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) { return service.OpenAIErrorWrapperLocal(err, "unmarshal_model_mapping_failed", http.StatusInternalServerError) } if modelMap[textRequest.Model] != "" { - isModelMapped = true + //isModelMapped = true textRequest.Model = modelMap[textRequest.Model] // set upstream model name //isModelMapped = true @@ -165,23 +166,25 @@ func TextHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) { adaptor.Init(relayInfo) var requestBody io.Reader - if relayInfo.ChannelType == common.ChannelTypeOpenAI && !isModelMapped { - body, err := common.GetRequestBody(c) - if err != nil { - return service.OpenAIErrorWrapperLocal(err, "get_request_body_failed", http.StatusInternalServerError) - } - requestBody = bytes.NewBuffer(body) - } else { - convertedRequest, err := adaptor.ConvertRequest(c, relayInfo, textRequest) - if err != nil { - return service.OpenAIErrorWrapperLocal(err, "convert_request_failed", http.StatusInternalServerError) - } - jsonData, err := json.Marshal(convertedRequest) - if err != nil { - return service.OpenAIErrorWrapperLocal(err, "json_marshal_failed", http.StatusInternalServerError) - } - requestBody = bytes.NewBuffer(jsonData) + //if relayInfo.ChannelType == common.ChannelTypeOpenAI && !isModelMapped { + // body, err := common.GetRequestBody(c) + // if err != nil { + // return service.OpenAIErrorWrapperLocal(err, "get_request_body_failed", http.StatusInternalServerError) + // } + // requestBody = bytes.NewBuffer(body) + //} else { + // + //} + + convertedRequest, err := adaptor.ConvertRequest(c, relayInfo, textRequest) + if err != nil { + return service.OpenAIErrorWrapperLocal(err, "convert_request_failed", http.StatusInternalServerError) } + jsonData, err := sonic.Marshal(convertedRequest) + if err != nil { + return service.OpenAIErrorWrapperLocal(err, "json_marshal_failed", http.StatusInternalServerError) + } + requestBody = bytes.NewBuffer(jsonData) statusCodeMappingStr := c.GetString("status_code_mapping") var httpResp *http.Response