fix: json issue
This commit is contained in:
parent
9d15776712
commit
d5dfacd8a6
@ -111,15 +111,14 @@ func testChannel(channel *model.Channel, request ChatRequest) (error, *OpenAIErr
|
|||||||
if !strings.HasPrefix(data, "data:") {
|
if !strings.HasPrefix(data, "data:") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
data = data[6:]
|
data = strings.TrimPrefix(data, "data:")
|
||||||
if !strings.HasPrefix(data, "[DONE]") {
|
if !strings.HasPrefix(data, "[DONE]") {
|
||||||
var streamResponse ChatCompletionsStreamResponse
|
var streamResponse ChatCompletionsStreamResponse
|
||||||
err := json.Unmarshal([]byte(data), &streamResponse)
|
err := json.Unmarshal([]byte(data), &streamResponse)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
return err, nil
|
for _, choice := range streamResponse.Choices {
|
||||||
}
|
responseText += choice.Delta.Content
|
||||||
for _, choice := range streamResponse.Choices {
|
}
|
||||||
responseText += choice.Delta.Content
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,19 +57,18 @@ func openaiStreamHandler(c *gin.Context, resp *http.Response, relayMode int) (*O
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dataChan <- data
|
dataChan <- data
|
||||||
data = data[6:]
|
data = strings.TrimPrefix(data, "data:")
|
||||||
if !strings.HasPrefix(data, "[DONE]") {
|
if !strings.HasPrefix(data, "[DONE]") {
|
||||||
switch relayMode {
|
switch relayMode {
|
||||||
case RelayModeChatCompletions:
|
case RelayModeChatCompletions:
|
||||||
var streamResponse ChatCompletionsStreamResponse
|
var streamResponse ChatCompletionsStreamResponse
|
||||||
err := json.Unmarshal([]byte(data), &streamResponse)
|
err := json.Unmarshal([]byte(data), &streamResponse)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
common.SysError("error unmarshalling stream response: " + err.Error())
|
for _, choice := range streamResponse.Choices {
|
||||||
|
responseText += choice.Delta.Content
|
||||||
|
}
|
||||||
continue // just ignore the error
|
continue // just ignore the error
|
||||||
}
|
}
|
||||||
for _, choice := range streamResponse.Choices {
|
|
||||||
responseText += choice.Delta.Content
|
|
||||||
}
|
|
||||||
case RelayModeCompletions:
|
case RelayModeCompletions:
|
||||||
var streamResponse CompletionsStreamResponse
|
var streamResponse CompletionsStreamResponse
|
||||||
err := json.Unmarshal([]byte(data), &streamResponse)
|
err := json.Unmarshal([]byte(data), &streamResponse)
|
||||||
|
Loading…
Reference in New Issue
Block a user