Skip to content

Commit

Permalink
fix whisper-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Calcium-Ion committed Nov 19, 2023
1 parent 8142875 commit cf663e7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
13 changes: 10 additions & 3 deletions controller/relay-audio.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,17 @@ func relayAudioHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode
group := c.GetString("group")

var audioRequest AudioRequest
err := common.UnmarshalBodyReusable(c, &audioRequest)
if err != nil {
return errorWrapper(err, "bind_request_body_failed", http.StatusBadRequest)
if !strings.HasPrefix(c.Request.URL.Path, "/v1/audio/transcriptions") {
err := common.UnmarshalBodyReusable(c, &audioRequest)
if err != nil {
return errorWrapper(err, "bind_request_body_failed", http.StatusBadRequest)
}
} else {
audioRequest = AudioRequest{
Model: "whisper-1",
}
}
//err := common.UnmarshalBodyReusable(c, &audioRequest)

// request validation
if audioRequest.Model == "" {
Expand Down
4 changes: 2 additions & 2 deletions controller/relay-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ func getImageToken(imageUrl MessageImageUrl) (int, error) {
return 0, err
}

defer response.Body.Close()

// 限制读取的字节数,防止下载整个图片
limitReader := io.LimitReader(response.Body, 8192)

response.Body.Close()

// 读取图片的头部信息来获取图片尺寸
config, _, err := image.DecodeConfig(limitReader)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion middleware/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ func Distribute() func(c *gin.Context) {
if modelRequest.Model == "" {
modelRequest.Model = "midjourney"
}
} else if !strings.HasPrefix(c.Request.URL.Path, "/v1/audio/transcriptions") {
err = common.UnmarshalBodyReusable(c, &modelRequest)
}
err = common.UnmarshalBodyReusable(c, &modelRequest)
if err != nil {
abortWithMessage(c, http.StatusBadRequest, "无效的请求")
return
Expand Down

0 comments on commit cf663e7

Please sign in to comment.