diff --git a/Anthropic.SDK.Tests/Anthropic.SDK.Tests.csproj b/Anthropic.SDK.Tests/Anthropic.SDK.Tests.csproj index 7649e1b..4fcf4c9 100644 --- a/Anthropic.SDK.Tests/Anthropic.SDK.Tests.csproj +++ b/Anthropic.SDK.Tests/Anthropic.SDK.Tests.csproj @@ -35,7 +35,7 @@ - + diff --git a/Anthropic.SDK.Tests/Messages.ChatClient.cs b/Anthropic.SDK.Tests/Messages.ChatClient.cs index 524c80b..5bf5158 100644 --- a/Anthropic.SDK.Tests/Messages.ChatClient.cs +++ b/Anthropic.SDK.Tests/Messages.ChatClient.cs @@ -155,7 +155,7 @@ public async Task TestThinkingStreamingRedactedConversation() messages.AddMessages(updates); - Assert.IsTrue(messages.Last().Contents.OfType().Any()); + Assert.IsTrue(messages.Last().Contents.OfType().Any(c => c.ProtectedData is not null)); messages.Add(new ChatMessage(ChatRole.User, "how many letters are in the word strawberry?")); diff --git a/Anthropic.SDK.Tests/VertexAI.ChatClient.cs b/Anthropic.SDK.Tests/VertexAI.ChatClient.cs index d237b27..a62d2d4 100644 --- a/Anthropic.SDK.Tests/VertexAI.ChatClient.cs +++ b/Anthropic.SDK.Tests/VertexAI.ChatClient.cs @@ -261,7 +261,7 @@ public async Task TestThinkingStreamingRedactedConversation() messages.AddMessages(updates); - Assert.IsTrue(messages.Last().Contents.OfType().Any()); + Assert.IsTrue(messages.Last().Contents.OfType().Any(c => c.ProtectedData is not null)); messages.Add(new ChatMessage(ChatRole.User, "how many letters are in the word strawberry?")); diff --git a/Anthropic.SDK/Anthropic.SDK.csproj b/Anthropic.SDK/Anthropic.SDK.csproj index cd49dff..c246de1 100644 --- a/Anthropic.SDK/Anthropic.SDK.csproj +++ b/Anthropic.SDK/Anthropic.SDK.csproj @@ -36,7 +36,7 @@ - + diff --git a/Anthropic.SDK/Extensions/MEAI.cs b/Anthropic.SDK/Extensions/MEAI.cs deleted file mode 100644 index 1b7dec4..0000000 --- a/Anthropic.SDK/Extensions/MEAI.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Anthropic.SDK.Extensions.MEAI -{ - public sealed class RedactedThinkingContent : Microsoft.Extensions.AI.AIContent - { - public RedactedThinkingContent(string data) - { - Data = data; - } - public string Data { get; set; } - } -} diff --git a/Anthropic.SDK/Messaging/ChatClientHelper.cs b/Anthropic.SDK/Messaging/ChatClientHelper.cs index 405d006..648d783 100644 --- a/Anthropic.SDK/Messaging/ChatClientHelper.cs +++ b/Anthropic.SDK/Messaging/ChatClientHelper.cs @@ -173,16 +173,19 @@ public static MessageParameters CreateMessageParameters(IChatClient client, IEnu }); break; - case Microsoft.Extensions.AI.TextReasoningContent textReasoningContent: - currentMessage.Content.Add(new Messaging.ThinkingContent() + case Microsoft.Extensions.AI.TextReasoningContent reasoningContent: + if (string.IsNullOrEmpty(reasoningContent.Text)) { - Thinking = textReasoningContent.Text, - Signature = textReasoningContent.AdditionalProperties[nameof(ThinkingContent.Signature)]?.ToString() - }); - break; - - case Anthropic.SDK.Extensions.MEAI.RedactedThinkingContent redactedThinkingContent: - currentMessage.Content.Add(new Messaging.RedactedThinkingContent() { Data = redactedThinkingContent.Data }); + currentMessage.Content.Add(new Messaging.RedactedThinkingContent() { Data = reasoningContent.ProtectedData }); + } + else + { + currentMessage.Content.Add(new Messaging.ThinkingContent() + { + Thinking = reasoningContent.Text, + Signature = reasoningContent.ProtectedData, + }); + } break; case Microsoft.Extensions.AI.TextContent textContent: @@ -256,15 +259,15 @@ public static List ProcessResponseContent(MessageResponse response) case Messaging.ThinkingContent thinkingContent: contents.Add(new Microsoft.Extensions.AI.TextReasoningContent(thinkingContent.Thinking) { - AdditionalProperties = new AdditionalPropertiesDictionary - { - [nameof(ThinkingContent.Signature)] = thinkingContent.Signature - } + ProtectedData = thinkingContent.Signature, }); break; case Messaging.RedactedThinkingContent redactedThinkingContent: - contents.Add(new Anthropic.SDK.Extensions.MEAI.RedactedThinkingContent(redactedThinkingContent.Data)); + contents.Add(new Microsoft.Extensions.AI.TextReasoningContent(null) + { + ProtectedData = redactedThinkingContent.Data, + }); break; case TextContent tc: diff --git a/Anthropic.SDK/Messaging/MessagesEndpoint.ChatClient.cs b/Anthropic.SDK/Messaging/MessagesEndpoint.ChatClient.cs index e9a80b8..be87da2 100644 --- a/Anthropic.SDK/Messaging/MessagesEndpoint.ChatClient.cs +++ b/Anthropic.SDK/Messaging/MessagesEndpoint.ChatClient.cs @@ -104,7 +104,7 @@ async IAsyncEnumerable IChatClient.GetStreamingResponseAsync if (!string.IsNullOrEmpty(response.ContentBlock?.Data)) { - update.Contents.Add(new SDK.Extensions.MEAI.RedactedThinkingContent(response.ContentBlock?.Data)); + update.Contents.Add(new TextReasoningContent(null) { ProtectedData = response.ContentBlock.Data }); } if (response.StreamStartMessage?.Usage is {} startStreamMessageUsage) @@ -128,10 +128,7 @@ async IAsyncEnumerable IChatClient.GetStreamingResponseAsync { update.Contents.Add(new TextReasoningContent(thinking) { - AdditionalProperties = new AdditionalPropertiesDictionary - { - [nameof(ThinkingContent.Signature)] = response.Delta.Signature - } + ProtectedData = response.Delta.Signature, }); } diff --git a/Anthropic.SDK/Messaging/VertexAIMessagesEndpoint.ChatClient.cs b/Anthropic.SDK/Messaging/VertexAIMessagesEndpoint.ChatClient.cs index 7073298..2981960 100644 --- a/Anthropic.SDK/Messaging/VertexAIMessagesEndpoint.ChatClient.cs +++ b/Anthropic.SDK/Messaging/VertexAIMessagesEndpoint.ChatClient.cs @@ -56,7 +56,7 @@ async IAsyncEnumerable IChatClient.GetStreamingResponseAsync if (!string.IsNullOrEmpty(response.ContentBlock?.Data)) { - update.Contents.Add(new SDK.Extensions.MEAI.RedactedThinkingContent(response.ContentBlock?.Data)); + update.Contents.Add(new TextReasoningContent(null) { ProtectedData = response.ContentBlock.Data }); } if (response.StreamStartMessage?.Usage is {} startStreamMessageUsage) @@ -80,10 +80,7 @@ async IAsyncEnumerable IChatClient.GetStreamingResponseAsync { update.Contents.Add(new Microsoft.Extensions.AI.TextReasoningContent(thinking) { - AdditionalProperties = new AdditionalPropertiesDictionary - { - [nameof(ThinkingContent.Signature)] = response.Delta.Signature - } + ProtectedData = response.Delta.Signature, }); }