Просмотр исходного кода

fix: empty completion issue caused by bad status code from upstream channel (#422)

Benny 2 лет назад
Родитель
Сommit
05e4f2b439
1 измененных файлов с 5 добавлено и 0 удалено
  1. 5 0
      controller/relay-text.go

+ 5 - 0
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")