From 0983837ff7dd7060a13d95e1a0f48c90a27fc8e7 Mon Sep 17 00:00:00 2001 From: ccnetcore Date: Thu, 22 Jan 2026 00:36:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=AD=A3=E7=A1=AE=E5=A4=84=E7=90=86=20A?= =?UTF-8?q?nthropic=20=E6=B5=81=E5=BC=8F=E5=93=8D=E5=BA=94=E7=BB=93?= =?UTF-8?q?=E6=9D=9F=E6=A0=87=E8=AE=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在解析流式数据时增加对 [DONE] 结束标记的判断,避免在流结束后继续反序列化数据导致异常。 --- .../ThorClaude/Chats/AnthropicChatCompletionsService.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/AnthropicChatCompletionsService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/AnthropicChatCompletionsService.cs index 83986cb8..ee84d1f6 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/AnthropicChatCompletionsService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiGateWay/Impl/ThorClaude/Chats/AnthropicChatCompletionsService.cs @@ -171,6 +171,12 @@ public class AnthropicChatCompletionsService( data = line[OpenAIConstant.Data.Length..].Trim(); + // 处理流结束标记 + if (data == "[DONE]") + { + break; + } + var result = JsonSerializer.Deserialize(data, ThorJsonSerializer.DefaultOptions);