correct output

This commit is contained in:
Roy Han 2024-07-29 17:12:39 -07:00
parent 7950053972
commit 23ff673bdc

View File

@ -1403,19 +1403,18 @@ func (s *Server) ChatHandler(c *gin.Context) {
if (req.Stream == nil || *req.Stream) && len(resp.Message.ToolCalls) > 0 { if (req.Stream == nil || *req.Stream) && len(resp.Message.ToolCalls) > 0 {
toolCh := make(chan any) toolCh := make(chan any)
go func() { go func() {
defer close(toolCh)
toolCalls := resp.Message.ToolCalls toolCalls := resp.Message.ToolCalls
for _, toolCall := range toolCalls[:len(toolCalls)-1] { for _, toolCall := range toolCalls {
chunk := api.ChatResponse{ toolCh <- api.ChatResponse{
Model: resp.Model, Model: resp.Model,
CreatedAt: resp.CreatedAt, CreatedAt: resp.CreatedAt,
Message: api.Message{Role: "assistant", ToolCalls: []api.ToolCall{toolCall}}, Message: api.Message{Role: "assistant", ToolCalls: []api.ToolCall{toolCall}},
DoneReason: "tool_calls",
} }
toolCh <- chunk
} }
resp.Message.ToolCalls = []api.ToolCall{toolCalls[len(toolCalls)-1]} resp.Message.ToolCalls = nil
resp.DoneReason = "tool_calls"
toolCh <- resp toolCh <- resp
close(toolCh)
}() }()
streamResponse(c, toolCh) streamResponse(c, toolCh)
return return