using var client = new AnthropicClient(apiKey);
var service = new WeatherService();
var tools = service.AsTools().AsAnthropicTools();
List<Message> messages = ["What is the current temperature in Dubai, UAE in Celsius?"];
var response = await client.CreateMessageAsync(
model: CreateMessageRequestModel.Claude35Sonnet20240620,
messages: messages,
maxTokens: 300,
metadata: null,
stopSequences: null,
system: "You are a helpful weather assistant.",
temperature: 0,
toolChoice: new ToolChoice
{
Type = ToolChoiceType.Auto,
Name = null,
},
tools: tools,
topK: 0,
topP: 0,
stream: false);
messages.Add(response.AsRequestMessage());
foreach (var toolUse in response.Content.Value2!
.Where(x => x.IsToolUse)
.Select(x => x.ToolUse))
{
var json = await service.CallAsync(
functionName: toolUse!.Name,
argumentsAsJson: toolUse.Input.AsJson());
messages.Add(json.AsToolCall(toolUse));
}
response = await client.CreateMessageAsync(
model: CreateMessageRequestModel.Claude35Sonnet20240620,
messages: messages,
maxTokens: 300,
metadata: null,
stopSequences: null,
system: "You are a helpful weather assistant.",
temperature: 0,
toolChoice: new ToolChoice
{
Type = ToolChoiceType.Auto,
Name = null,
},
tools: tools,
topK: 0,
topP: 0,
stream: false);
Console.WriteLine(response.AsSimpleText());