fix: skip JSON deserialization when accessing transcriptions and translations (#718)
* fix: Skip JSON deserialization when accessing transcriptions and translations. * chore: update impl --------- Co-authored-by: JustSong <songquanpeng@foxmail.com>
This commit is contained in:
parent
54e5f8ecd2
commit
969f539777
@ -5,6 +5,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"io"
|
"io"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func UnmarshalBodyReusable(c *gin.Context, v any) error {
|
func UnmarshalBodyReusable(c *gin.Context, v any) error {
|
||||||
@ -16,7 +17,13 @@ func UnmarshalBodyReusable(c *gin.Context, v any) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = json.Unmarshal(requestBody, &v)
|
contentType := c.Request.Header.Get("Content-Type")
|
||||||
|
if strings.HasPrefix(contentType, "application/json") {
|
||||||
|
err = json.Unmarshal(requestBody, &v)
|
||||||
|
} else {
|
||||||
|
// skip for now
|
||||||
|
// TODO: someday non json request have variant model, we will need to implementation this
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -201,9 +201,9 @@ func Relay(c *gin.Context) {
|
|||||||
relayMode = RelayModeEdits
|
relayMode = RelayModeEdits
|
||||||
} else if strings.HasPrefix(c.Request.URL.Path, "/v1/audio/speech") {
|
} else if strings.HasPrefix(c.Request.URL.Path, "/v1/audio/speech") {
|
||||||
relayMode = RelayModeAudioSpeech
|
relayMode = RelayModeAudioSpeech
|
||||||
} else if strings.HasPrefix(c.Request.URL.Path, "/v1/audio/transcription") {
|
} else if strings.HasPrefix(c.Request.URL.Path, "/v1/audio/transcriptions") {
|
||||||
relayMode = RelayModeAudioTranscription
|
relayMode = RelayModeAudioTranscription
|
||||||
} else if strings.HasPrefix(c.Request.URL.Path, "/v1/audio/translation") {
|
} else if strings.HasPrefix(c.Request.URL.Path, "/v1/audio/translations") {
|
||||||
relayMode = RelayModeAudioTranslation
|
relayMode = RelayModeAudioTranslation
|
||||||
}
|
}
|
||||||
var err *OpenAIErrorWithStatusCode
|
var err *OpenAIErrorWithStatusCode
|
||||||
|
Loading…
Reference in New Issue
Block a user