From fa89a3d60b72e619e78d9fcc6a4bab6b0dee799a Mon Sep 17 00:00:00 2001 From: Buer <42402987+MartialBE@users.noreply.github.com> Date: Sun, 10 Mar 2024 02:37:47 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20missing=20toolcalls=20par?= =?UTF-8?q?ameter=20in=20stream=20response=20(#95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- providers/mistral/chat.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/providers/mistral/chat.go b/providers/mistral/chat.go index 63b62427..a8b532d1 100644 --- a/providers/mistral/chat.go +++ b/providers/mistral/chat.go @@ -131,6 +131,24 @@ func (h *mistralStreamHandler) handlerStream(rawLine *[]byte, dataChan chan stri *h.Usage = *mistralResponse.Usage } + stop := false + for _, choice := range mistralResponse.ChatCompletionStreamResponse.Choices { + if choice.Delta.ToolCalls != nil { + choices := choice.ConvertOpenaiStream() + for _, newChoice := range choices { + chatCompletionCopy := mistralResponse + chatCompletionCopy.Choices = []types.ChatCompletionStreamChoice{newChoice} + responseBody, _ := json.Marshal(chatCompletionCopy.ChatCompletionStreamResponse) + dataChan <- string(responseBody) + } + stop = true + } + } + + if stop { + return + } + responseBody, _ := json.Marshal(mistralResponse.ChatCompletionStreamResponse) dataChan <- string(responseBody)