diff --git a/Anthropic.SDK.Tests/Anthropic.SDK.Tests.csproj b/Anthropic.SDK.Tests/Anthropic.SDK.Tests.csproj index c397e73..16d28ab 100644 --- a/Anthropic.SDK.Tests/Anthropic.SDK.Tests.csproj +++ b/Anthropic.SDK.Tests/Anthropic.SDK.Tests.csproj @@ -35,13 +35,13 @@ - + - - + + diff --git a/Anthropic.SDK.Tests/Messages.ChatClient.cs b/Anthropic.SDK.Tests/Messages.ChatClient.cs index 6dd55a0..6a1d1b2 100644 --- a/Anthropic.SDK.Tests/Messages.ChatClient.cs +++ b/Anthropic.SDK.Tests/Messages.ChatClient.cs @@ -1,4 +1,5 @@ -using System.Diagnostics; +using System.Collections.ObjectModel; +using System.Diagnostics; using System.IO; using System.Reflection; using System.Text; @@ -232,6 +233,28 @@ public async Task TestNonStreamingFunctionCalls() res.Text); } + [TestMethod] + public async Task TestNonStreamingWebSearchCalls() + { + IChatClient client = new AnthropicClient().Messages + .AsBuilder() + .UseFunctionInvocation() + .Build(); + + ChatOptions options = new() + { + ModelId = AnthropicModels.Claude4Sonnet, + MaxOutputTokens = 5000, + Tools = [new HostedWebSearchTool()] + }; + + var res = await client.GetResponseAsync("What is the weather like in San Francisco, CA right now?", options); + + Assert.IsTrue( + res.Text.Contains("San Francisco") is true, + res.Text); + } + [TestMethod] public async Task TestStreamingFunctionCalls() { diff --git a/Anthropic.SDK/Anthropic.SDK.csproj b/Anthropic.SDK/Anthropic.SDK.csproj index d51a115..88db21a 100644 --- a/Anthropic.SDK/Anthropic.SDK.csproj +++ b/Anthropic.SDK/Anthropic.SDK.csproj @@ -14,12 +14,12 @@ Claude, AI, ML, API, Anthropic Claude API - Web Search, MCP Servers, and Claude 4 Models, Minor Bug Fixes + Improvements to Microsoft.Extensions.AI.Abstractions integration Anthropic.SDK - 5.4.1 - 5.4.1.0 - 5.4.1.0 + 5.4.2 + 5.4.2.0 + 5.4.2.0 True README.md icon.png @@ -34,7 +34,7 @@ - + diff --git a/Anthropic.SDK/Messaging/ChatClientHelper.cs b/Anthropic.SDK/Messaging/ChatClientHelper.cs index 9898396..5117cb3 100644 --- a/Anthropic.SDK/Messaging/ChatClientHelper.cs +++ b/Anthropic.SDK/Messaging/ChatClientHelper.cs @@ -86,6 +86,9 @@ public static MessageParameters CreateMessageParameters(IChatClient client, IEnu case HostedCodeInterpreterTool ci: tools.Add(Common.Tool.CodeInterpreter); break; + case HostedWebSearchTool wt: + tools.Add(ServerTools.GetWebSearchTool(5)); + break; } } }