From bf0290ee1921fefdca0f287813164e8d3b697151 Mon Sep 17 00:00:00 2001 From: "jie.zhu" <981975491@qq.com> Date: Tue, 25 Mar 2025 12:09:38 +0800 Subject: [PATCH 1/2] some implement of streaming api may return "" as finish_reason such as o3 (https://o3.fan/). --- ...reateChatCompletionStreamResponseChoice.Serialization.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Custom/Chat/Streaming/InternalCreateChatCompletionStreamResponseChoice.Serialization.cs b/src/Custom/Chat/Streaming/InternalCreateChatCompletionStreamResponseChoice.Serialization.cs index 5d3b87e6..0312bb6b 100644 --- a/src/Custom/Chat/Streaming/InternalCreateChatCompletionStreamResponseChoice.Serialization.cs +++ b/src/Custom/Chat/Streaming/InternalCreateChatCompletionStreamResponseChoice.Serialization.cs @@ -81,12 +81,14 @@ internal static InternalCreateChatCompletionStreamResponseChoice DeserializeInte } if (property.NameEquals("finish_reason"u8)) { - if (property.Value.ValueKind == JsonValueKind.Null) + var propertyValue = property.Value; + string propertyValueString; + if (propertyValue.ValueKind == JsonValueKind.Null||(propertyValueString=propertyValue.GetString())?.Trim()==string.Empty) { finishReason = null; continue; } - finishReason = property.Value.GetString().ToChatFinishReason(); + finishReason = propertyValueString.ToChatFinishReason(); continue; } if (property.NameEquals("index"u8)) From 7e2209fc1d91f8959a3d85cf4b239a303d69b649 Mon Sep 17 00:00:00 2001 From: "jie.zhu" <981975491@qq.com> Date: Tue, 25 Mar 2025 12:12:26 +0800 Subject: [PATCH 2/2] some implement of streaming api may return "" as finish_reason such as o3 (https://o3.fan/). --- ...nalCreateChatCompletionStreamResponseChoice.Serialization.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Custom/Chat/Streaming/InternalCreateChatCompletionStreamResponseChoice.Serialization.cs b/src/Custom/Chat/Streaming/InternalCreateChatCompletionStreamResponseChoice.Serialization.cs index 0312bb6b..58bc9265 100644 --- a/src/Custom/Chat/Streaming/InternalCreateChatCompletionStreamResponseChoice.Serialization.cs +++ b/src/Custom/Chat/Streaming/InternalCreateChatCompletionStreamResponseChoice.Serialization.cs @@ -83,7 +83,7 @@ internal static InternalCreateChatCompletionStreamResponseChoice DeserializeInte { var propertyValue = property.Value; string propertyValueString; - if (propertyValue.ValueKind == JsonValueKind.Null||(propertyValueString=propertyValue.GetString())?.Trim()==string.Empty) + if (propertyValue.ValueKind == JsonValueKind.Null||string.IsNullOrEmpty((propertyValueString=propertyValue.GetString())?.Trim())) { finishReason = null; continue;