Change sample to use official Anthropic C# package (#2471)

Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
This commit is contained in:
Stephen Toub
2025-11-28 14:10:54 -05:00
committed by GitHub
Unverified
parent 67de7bcd93
commit a3909b8b5b
3 changed files with 8 additions and 12 deletions
-1
View File
@@ -97,7 +97,6 @@
<!-- MCP -->
<PackageVersion Include="ModelContextProtocol" Version="0.4.0-preview.3" />
<!-- Inference SDKs -->
<PackageVersion Include="Anthropic.SDK" Version="5.8.0" />
<PackageVersion Include="AWSSDK.Extensions.Bedrock.MEAI" Version="4.0.4.6" />
<PackageVersion Include="Microsoft.ML.OnnxRuntimeGenAI" Version="0.10.0" />
<PackageVersion Include="OllamaSharp" Version="5.4.8" />
@@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Anthropic.SDK" />
<PackageReference Include="Anthropic" />
<PackageReference Include="AWSSDK.Extensions.Bedrock.MEAI" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" />
</ItemGroup>
@@ -12,19 +12,16 @@ const string Topic = "Goldendoodles make the best pets.";
IChatClient aws = new AmazonBedrockRuntimeClient(
Environment.GetEnvironmentVariable("BEDROCK_ACCESSKEY"!),
Environment.GetEnvironmentVariable("BEDROCK_SECRETACCESSKEY")!,
Amazon.RegionEndpoint.USEast1).AsIChatClient("amazon.nova-pro-v1:0");
Amazon.RegionEndpoint.USEast1)
.AsIChatClient("amazon.nova-pro-v1:0");
IChatClient anthropic = new Anthropic.SDK.AnthropicClient(
Environment.GetEnvironmentVariable("ANTHROPIC_APIKEY")!).Messages.AsBuilder()
.ConfigureOptions(o =>
{
o.ModelId ??= "claude-sonnet-4-20250514";
o.MaxOutputTokens ??= 10 * 1024;
})
.Build();
IChatClient anthropic = new Anthropic.AnthropicClient(
new() { APIKey = Environment.GetEnvironmentVariable("ANTHROPIC_APIKEY") })
.AsIChatClient("claude-sonnet-4-20250514");
IChatClient openai = new OpenAI.OpenAIClient(
Environment.GetEnvironmentVariable("OPENAI_APIKEY")!).GetChatClient("gpt-4o-mini").AsIChatClient();
Environment.GetEnvironmentVariable("OPENAI_APIKEY")!).GetChatClient("gpt-4o-mini")
.AsIChatClient();
// Define our agents.
AIAgent researcher = new ChatClientAgent(aws,