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]") {