improvement: azure api result transformation

This commit is contained in:
andie 2023-10-31 14:52:02 +08:00
parent 3bfbd0bc2b
commit 9d5d4eb486

View File

@ -40,6 +40,14 @@ func openaiStreamHandler(c *gin.Context, resp *http.Response, relayMode int) (*O
if data[:6] != "data: " && data[:6] != "[DONE]" {
continue
}
// Ignore invalid results in the first line of azure api results.
if c.GetInt("channel") == common.ChannelTypeAzure && !strings.HasPrefix(data[6:], "[DONE]") {
var streamResponse ChatCompletionsStreamResponse
err := json.Unmarshal([]byte(data[6:]), &streamResponse)
if err == nil && streamResponse.Id == "" {
continue
}
}
dataChan <- data
data = data[6:]
if !strings.HasPrefix(data, "[DONE]") {