From 4d251b08b00b65668c3789351b7fb295b40cc032 Mon Sep 17 00:00:00 2001 From: Ian Li Date: Sat, 18 Nov 2023 10:30:06 +0800 Subject: [PATCH] fix: Skip JSON deserialization when accessing transcriptions and translations. --- controller/relay.go | 4 ++-- middleware/distributor.go | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/controller/relay.go b/controller/relay.go index 863267b4..504ee8ca 100644 --- a/controller/relay.go +++ b/controller/relay.go @@ -201,9 +201,9 @@ func Relay(c *gin.Context) { relayMode = RelayModeEdits } else if strings.HasPrefix(c.Request.URL.Path, "/v1/audio/speech") { 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 - } else if strings.HasPrefix(c.Request.URL.Path, "/v1/audio/translation") { + } else if strings.HasPrefix(c.Request.URL.Path, "/v1/audio/translations") { relayMode = RelayModeAudioTranslation } var err *OpenAIErrorWithStatusCode diff --git a/middleware/distributor.go b/middleware/distributor.go index c4ddc3a0..7106e839 100644 --- a/middleware/distributor.go +++ b/middleware/distributor.go @@ -40,7 +40,10 @@ func Distribute() func(c *gin.Context) { } else { // Select a channel for the user var modelRequest ModelRequest - err := common.UnmarshalBodyReusable(c, &modelRequest) + var err error + if !strings.HasPrefix(c.Request.URL.Path, "/v1/audio/transcriptions") && !strings.HasPrefix(c.Request.URL.Path, "/v1/audio/translations") { + err = common.UnmarshalBodyReusable(c, &modelRequest) + } if err != nil { abortWithMessage(c, http.StatusBadRequest, "无效的请求") return