|
@@ -6,6 +6,7 @@ import (
|
|
|
"encoding/json"
|
|
"encoding/json"
|
|
|
"errors"
|
|
"errors"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
+ "github.com/bytedance/sonic"
|
|
|
"io"
|
|
"io"
|
|
|
"math"
|
|
"math"
|
|
|
"net/http"
|
|
"net/http"
|
|
@@ -76,7 +77,7 @@ func TextHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// map model name
|
|
// map model name
|
|
|
- isModelMapped := false
|
|
|
|
|
|
|
+ //isModelMapped := false
|
|
|
modelMapping := c.GetString("model_mapping")
|
|
modelMapping := c.GetString("model_mapping")
|
|
|
//isModelMapped := false
|
|
//isModelMapped := false
|
|
|
if modelMapping != "" && modelMapping != "{}" {
|
|
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)
|
|
return service.OpenAIErrorWrapperLocal(err, "unmarshal_model_mapping_failed", http.StatusInternalServerError)
|
|
|
}
|
|
}
|
|
|
if modelMap[textRequest.Model] != "" {
|
|
if modelMap[textRequest.Model] != "" {
|
|
|
- isModelMapped = true
|
|
|
|
|
|
|
+ //isModelMapped = true
|
|
|
textRequest.Model = modelMap[textRequest.Model]
|
|
textRequest.Model = modelMap[textRequest.Model]
|
|
|
// set upstream model name
|
|
// set upstream model name
|
|
|
//isModelMapped = true
|
|
//isModelMapped = true
|
|
@@ -165,23 +166,25 @@ func TextHelper(c *gin.Context) (openaiErr *dto.OpenAIErrorWithStatusCode) {
|
|
|
adaptor.Init(relayInfo)
|
|
adaptor.Init(relayInfo)
|
|
|
var requestBody io.Reader
|
|
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")
|
|
statusCodeMappingStr := c.GetString("status_code_mapping")
|
|
|
var httpResp *http.Response
|
|
var httpResp *http.Response
|