From cf91cf1b14cd03f4f7d326a34306109ee74bddd2 Mon Sep 17 00:00:00 2001 From: feitianbubu Date: Fri, 8 Aug 2025 08:36:56 +0800 Subject: [PATCH] fix: ensure last message is sent successfully --- relay/channel/openai/helper.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/relay/channel/openai/helper.go b/relay/channel/openai/helper.go index 11a34ca5..696c5cb0 100644 --- a/relay/channel/openai/helper.go +++ b/relay/channel/openai/helper.go @@ -3,6 +3,7 @@ package openai import ( "encoding/json" "errors" + "github.com/samber/lo" "net/http" "one-api/common" "one-api/dto" @@ -186,7 +187,9 @@ func handleLastResponse(lastStreamData string, responseId *string, createAt *int *containStreamUsage = true *usage = lastStreamResponse.Usage if !info.ShouldIncludeUsage { - *shouldSendLastResp = false + *shouldSendLastResp = lo.SomeBy(lastStreamResponse.Choices, func(choice dto.ChatCompletionsStreamResponseChoice) bool { + return choice.Delta.GetContentString() != "" || choice.Delta.GetReasoningContent() != "" + }) } }