From 47cb77de5399b9b57a5a16a6f07276a88896240a Mon Sep 17 00:00:00 2001 From: ckt1031 <65409152+ckt1031@users.noreply.github.com> Date: Thu, 13 Jul 2023 20:49:57 +0800 Subject: [PATCH] fix: better text phrasing --- controller/channel-test.go | 8 +++++++- controller/relay-text.go | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/controller/channel-test.go b/controller/channel-test.go index 7f3a3025..87d57a90 100644 --- a/controller/channel-test.go +++ b/controller/channel-test.go @@ -83,12 +83,18 @@ func testChannel(channel *model.Channel, request ChatRequest) error { common.SysError("invalid stream response: " + data) continue } + if !strings.HasPrefix(data, "data:") { + continue + } data = data[6:] if !strings.HasPrefix(data, "[DONE]") { var streamResponse ChatCompletionsStreamResponse err = json.Unmarshal([]byte(data), &streamResponse) if err != nil { - common.SysError("error unmarshalling stream response: " + err.Error()) + // Prinnt the body in string + buf := new(bytes.Buffer) + buf.ReadFrom(resp.Body) + common.SysError("error unmarshalling stream response: " + err.Error() + " " + buf.String()) return err } for _, choice := range streamResponse.Choices { diff --git a/controller/relay-text.go b/controller/relay-text.go index fd66226a..de7f1768 100644 --- a/controller/relay-text.go +++ b/controller/relay-text.go @@ -278,6 +278,9 @@ func relayTextHelper(c *gin.Context, relayMode int) *OpenAIErrorWithStatusCode { common.SysError("invalid stream response: " + data) continue } + if !strings.HasPrefix(data, "data:") { + continue + } dataChan <- data data = data[6:] if !strings.HasPrefix(data, "[DONE]") {