Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Anthropic.SDK.Tests/Anthropic.SDK.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<ItemGroup>
<PackageReference Include="Google.Cloud.AIPlatform.V1" Version="3.24.0" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.9.0" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.9.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
Expand Down
2 changes: 1 addition & 1 deletion Anthropic.SDK.Tests/Messages.ChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public async Task TestThinkingStreamingRedactedConversation()

messages.AddMessages(updates);

Assert.IsTrue(messages.Last().Contents.OfType<Extensions.MEAI.RedactedThinkingContent>().Any());
Assert.IsTrue(messages.Last().Contents.OfType<TextReasoningContent>().Any(c => c.ProtectedData is not null));

messages.Add(new ChatMessage(ChatRole.User, "how many letters are in the word strawberry?"));

Expand Down
2 changes: 1 addition & 1 deletion Anthropic.SDK.Tests/VertexAI.ChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public async Task TestThinkingStreamingRedactedConversation()

messages.AddMessages(updates);

Assert.IsTrue(messages.Last().Contents.OfType<Extensions.MEAI.RedactedThinkingContent>().Any());
Assert.IsTrue(messages.Last().Contents.OfType<TextReasoningContent>().Any(c => c.ProtectedData is not null));

messages.Add(new ChatMessage(ChatRole.User, "how many letters are in the word strawberry?"));

Expand Down
2 changes: 1 addition & 1 deletion Anthropic.SDK/Anthropic.SDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.9.0" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.9.1" />
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
</ItemGroup>

Expand Down
15 changes: 0 additions & 15 deletions Anthropic.SDK/Extensions/MEAI.cs

This file was deleted.

31 changes: 17 additions & 14 deletions Anthropic.SDK/Messaging/ChatClientHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -256,15 +259,15 @@ public static List<AIContent> 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:
Expand Down
7 changes: 2 additions & 5 deletions Anthropic.SDK/Messaging/MessagesEndpoint.ChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ async IAsyncEnumerable<ChatResponseUpdate> 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)
Expand All @@ -128,10 +128,7 @@ async IAsyncEnumerable<ChatResponseUpdate> IChatClient.GetStreamingResponseAsync
{
update.Contents.Add(new TextReasoningContent(thinking)
{
AdditionalProperties = new AdditionalPropertiesDictionary
{
[nameof(ThinkingContent.Signature)] = response.Delta.Signature
}
ProtectedData = response.Delta.Signature,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ async IAsyncEnumerable<ChatResponseUpdate> 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)
Expand All @@ -80,10 +80,7 @@ async IAsyncEnumerable<ChatResponseUpdate> IChatClient.GetStreamingResponseAsync
{
update.Contents.Add(new Microsoft.Extensions.AI.TextReasoningContent(thinking)
{
AdditionalProperties = new AdditionalPropertiesDictionary
{
[nameof(ThinkingContent.Signature)] = response.Delta.Signature
}
ProtectedData = response.Delta.Signature,
});
}

Expand Down
Loading