From 67c64e71c800a76b2fa7a5b6eb51e89a14479b0c Mon Sep 17 00:00:00 2001 From: JustSong Date: Wed, 20 Dec 2023 21:45:33 +0800 Subject: [PATCH] fix: fix max_tokens check --- controller/relay-text.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/controller/relay-text.go b/controller/relay-text.go index b53b0caa3f..c49a2abea7 100644 --- a/controller/relay-text.go +++ b/controller/relay-text.go @@ -58,6 +58,9 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { if err != nil { return errorWrapper(err, "bind_request_body_failed", http.StatusBadRequest) } + if textRequest.MaxTokens < 0 || textRequest.MaxTokens > math.MaxInt32/2 { + return errorWrapper(errors.New("max_tokens is invalid"), "invalid_max_tokens", http.StatusBadRequest) + } if relayMode == RelayModeModerations && textRequest.Model == "" { textRequest.Model = "text-moderation-latest" }