Skip to content

Commit

Permalink
🐛 fix: cohere stream error (MartialBE#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartialBE committed Jul 29, 2024
1 parent e2f7951 commit 28ab819
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion providers/cohere/chat.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,13 @@ func ConvertToChatOpenai(provider base.ProviderInterface, response *CohereRespon
// 转换为OpenAI聊天流式请求体
func (h *CohereStreamHandler) HandlerStream(rawLine *[]byte, dataChan chan string, errChan chan error) {
// 如果rawLine 前缀不为data:,则直接返回
if !strings.HasPrefix(string(*rawLine), "{") {
if !strings.HasPrefix(string(*rawLine), "data: ") {
*rawLine = nil
return
}

*rawLine = (*rawLine)[6:]

var cohereResponse CohereStreamResponse
err := json.Unmarshal(*rawLine, &cohereResponse)
if err != nil {
Expand Down

0 comments on commit 28ab819

Please sign in to comment.