fix: 正确处理 Anthropic 流式响应结束标记
在解析流式数据时增加对 [DONE] 结束标记的判断,避免在流结束后继续反序列化数据导致异常。
This commit is contained in:
@@ -171,6 +171,12 @@ public class AnthropicChatCompletionsService(
|
||||
|
||||
data = line[OpenAIConstant.Data.Length..].Trim();
|
||||
|
||||
// 处理流结束标记
|
||||
if (data == "[DONE]")
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
var result = JsonSerializer.Deserialize<AnthropicStreamDto>(data,
|
||||
ThorJsonSerializer.DefaultOptions);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user