varclient=newXaiClient(apiKey);varmodelId=GetModelId();// Define a function tool with a JSON Schema for its parameters.vartools=newList<ChatCompletionTool>{newChatCompletionTool{Type=ChatCompletionToolType.Function,Function=newFunctionDefinition{Name="get_weather",Description="Get the current weather for a location.",Parameters=JsonSerializer.Deserialize<JsonElement>("""{"type":"object","properties":{"location":{"type":"string","description":"The city name."}},"required":["location"]}"""),},},};// Send a message that should trigger the tool call.varresponse=awaitclient.Chat.CreateChatCompletionAsync(model:modelId,messages:[newChatCompletionMessage{Role=ChatCompletionMessageRole.User,Content="What is the weather in San Francisco?",},],tools:tools,toolChoice:newOneOf<CreateChatCompletionRequestToolChoice?,ChatCompletionNamedToolChoice>(CreateChatCompletionRequestToolChoice.Auto));varchoice=response.Choices![0];// Inspect the tool call the model wants to make.vartoolCall=choice.Message!.ToolCalls![0];Console.WriteLine($"{toolCall.Function.Name}({toolCall.Function.Arguments})");