From 05e4f2b439033ebcd2edb77b07e8e7f76d332812 Mon Sep 17 00:00:00 2001 From: Benny Date: Sat, 19 Aug 2023 17:58:45 +0800 Subject: [PATCH] fix: empty completion issue caused by bad status code from upstream channel (#422) --- controller/relay-text.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/controller/relay-text.go b/controller/relay-text.go index e061d38771..6ebe75e96c 100644 --- a/controller/relay-text.go +++ b/controller/relay-text.go @@ -317,6 +317,11 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { isStream = isStream || strings.HasPrefix(resp.Header.Get("Content-Type"), "text/event-stream") } + if resp.StatusCode != http.StatusOK { + return errorWrapper( + fmt.Errorf("bad status code: %d", resp.StatusCode), "bad_status_code", resp.StatusCode) + } + var textResponse TextResponse tokenName := c.GetString("token_name") channelId := c.GetInt("channel_id")