From 23ff673bdcadc3c77f3e1cc5f873427d8a19cfb0 Mon Sep 17 00:00:00 2001 From: Roy Han Date: Mon, 29 Jul 2024 17:12:39 -0700 Subject: [PATCH] correct output --- server/routes.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/server/routes.go b/server/routes.go index 63eac5634..01d161ab4 100644 --- a/server/routes.go +++ b/server/routes.go @@ -1403,19 +1403,18 @@ func (s *Server) ChatHandler(c *gin.Context) { if (req.Stream == nil || *req.Stream) && len(resp.Message.ToolCalls) > 0 { toolCh := make(chan any) go func() { + defer close(toolCh) toolCalls := resp.Message.ToolCalls - for _, toolCall := range toolCalls[:len(toolCalls)-1] { - chunk := api.ChatResponse{ - Model: resp.Model, - CreatedAt: resp.CreatedAt, - Message: api.Message{Role: "assistant", ToolCalls: []api.ToolCall{toolCall}}, - DoneReason: "tool_calls", + for _, toolCall := range toolCalls { + toolCh <- api.ChatResponse{ + Model: resp.Model, + CreatedAt: resp.CreatedAt, + Message: api.Message{Role: "assistant", ToolCalls: []api.ToolCall{toolCall}}, } - toolCh <- chunk } - resp.Message.ToolCalls = []api.ToolCall{toolCalls[len(toolCalls)-1]} + resp.Message.ToolCalls = nil + resp.DoneReason = "tool_calls" toolCh <- resp - close(toolCh) }() streamResponse(c, toolCh) return