|
@@ -17,6 +17,7 @@ import (
|
|
|
"one-api/relay/helper"
|
|
"one-api/relay/helper"
|
|
|
"one-api/service"
|
|
"one-api/service"
|
|
|
"one-api/setting"
|
|
"one-api/setting"
|
|
|
|
|
+ "one-api/setting/model_setting"
|
|
|
"strings"
|
|
"strings"
|
|
|
"time"
|
|
"time"
|
|
|
|
|
|
|
@@ -152,33 +153,32 @@ 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)
|
|
|
|
|
|
|
+ if model_setting.GetGlobalSettings().PassThroughRequestEnabled {
|
|
|
|
|
+ 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)
|
|
|
}
|
|
}
|
|
|
- requestBody = bytes.NewBuffer(jsonData)
|
|
|
|
|
|
|
|
|
|
- statusCodeMappingStr := c.GetString("status_code_mapping")
|
|
|
|
|
var httpResp *http.Response
|
|
var httpResp *http.Response
|
|
|
resp, err := adaptor.DoRequest(c, relayInfo, requestBody)
|
|
resp, err := adaptor.DoRequest(c, relayInfo, requestBody)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
return service.OpenAIErrorWrapper(err, "do_request_failed", http.StatusInternalServerError)
|
|
return service.OpenAIErrorWrapper(err, "do_request_failed", http.StatusInternalServerError)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ statusCodeMappingStr := c.GetString("status_code_mapping")
|
|
|
|
|
+
|
|
|
if resp != nil {
|
|
if resp != nil {
|
|
|
httpResp = resp.(*http.Response)
|
|
httpResp = resp.(*http.Response)
|
|
|
relayInfo.IsStream = relayInfo.IsStream || strings.HasPrefix(httpResp.Header.Get("Content-Type"), "text/event-stream")
|
|
relayInfo.IsStream = relayInfo.IsStream || strings.HasPrefix(httpResp.Header.Get("Content-Type"), "text/event-stream")
|