From e14fb02fb90f197ebcf5babebe9c2a0302318608 Mon Sep 17 00:00:00 2001 From: Zhang Minghan Date: Sun, 18 Feb 2024 20:52:38 +0800 Subject: [PATCH] fix: filter empty chunk --- globals/method.go | 5 +++++ manager/chat_completions.go | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 globals/method.go diff --git a/globals/method.go b/globals/method.go new file mode 100644 index 0000000..28e7b29 --- /dev/null +++ b/globals/method.go @@ -0,0 +1,5 @@ +package globals + +func (c *Chunk) IsEmpty() bool { + return len(c.Content) == 0 && c.ToolCall == nil && c.FunctionCall == nil +} diff --git a/manager/chat_completions.go b/manager/chat_completions.go index 35f0f6a..a87ab0a 100644 --- a/manager/chat_completions.go +++ b/manager/chat_completions.go @@ -198,7 +198,10 @@ func sendStreamTranshipmentResponse(c *gin.Context, form RelayForm, messages []g cache, buffer, group, getChatProps(form, messages, buffer, plan), func(data *globals.Chunk) error { buffer.WriteChunk(data) - partial <- getStreamTranshipmentForm(id, created, form, data, buffer, false, nil) + + if !data.IsEmpty() { + partial <- getStreamTranshipmentForm(id, created, form, data, buffer, false, nil) + } return nil }, )