mirror of
https://github.com/songquanpeng/one-api.git
synced 2025-09-19 18:16:38 +08:00
style: Upgrade relay controller text package
- Refactoring of the Text controller.
This commit is contained in:
parent
609a6cb4b2
commit
b9972e0aa4
@ -53,6 +53,7 @@ func RelayTextHelper(c *gin.Context) *model.ErrorWithStatusCode {
|
||||
|
||||
// get request body
|
||||
var requestBody io.Reader
|
||||
var jsonData []byte
|
||||
if meta.APIType == constant.APITypeOpenAI {
|
||||
// no need to convert request for openai
|
||||
if isModelMapped {
|
||||
@ -69,7 +70,7 @@ func RelayTextHelper(c *gin.Context) *model.ErrorWithStatusCode {
|
||||
if err != nil {
|
||||
return openai.ErrorWrapper(err, "convert_request_failed", http.StatusInternalServerError)
|
||||
}
|
||||
jsonData, err := json.Marshal(convertedRequest)
|
||||
jsonData, err = json.Marshal(convertedRequest)
|
||||
if err != nil {
|
||||
return openai.ErrorWrapper(err, "json_marshal_failed", http.StatusInternalServerError)
|
||||
}
|
||||
@ -85,6 +86,7 @@ func RelayTextHelper(c *gin.Context) *model.ErrorWithStatusCode {
|
||||
meta.IsStream = meta.IsStream || strings.HasPrefix(resp.Header.Get("Content-Type"), "text/event-stream")
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
util.ReturnPreConsumedQuota(ctx, preConsumedQuota, meta.TokenId)
|
||||
logger.Error(ctx, fmt.Sprintf("relay text [%d] <- %q", resp.StatusCode, string(jsonData)))
|
||||
return util.RelayErrorHandler(resp)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user