.NET: Add more console based getting started samples (#507)

* Add more console based getting started samples

* Simplify function calling and approavls samples and some minor renaming based on PR feedback.

* Cover streaming with comments for aprovals sample.

* Remove extra line break.

* Update getting started samples list in readme.

* Address PR comments

* Address PR comments.
This commit is contained in:
westey
2025-08-28 14:14:25 +00:00
committed by GitHub
parent 6b22b6bbc7
commit bbea3c00f8
28 changed files with 634 additions and 900 deletions
+4 -4
View File
@@ -8,17 +8,17 @@ using Microsoft.Extensions.AI;
using Microsoft.Extensions.AI.Agents;
using OpenAI;
var azureOpenAIEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
var azureOpenAIDeploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
var endpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT") ?? throw new InvalidOperationException("AZURE_OPENAI_ENDPOINT is not set.");
var deploymentName = Environment.GetEnvironmentVariable("AZURE_OPENAI_DEPLOYMENT_NAME") ?? "gpt-4o-mini";
[Description("Get the weather for a given location.")]
static string GetWeather([Description("The location to get the weather for.")] string location)
=> $"The weather in {location} is cloudy with a high of 15°C.";
AIAgent agent = new AzureOpenAIClient(
new Uri(azureOpenAIEndpoint),
new Uri(endpoint),
new AzureCliCredential())
.GetChatClient(azureOpenAIDeploymentName)
.GetChatClient(deploymentName)
.CreateAIAgent(
instructions: "You are a helpful assistant, you can help the user with weather information.",
tools: [AIFunctionFactory.Create(GetWeather)]);