forked from microsoft/Generative-AI-for-beginners-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
26 lines (20 loc) · 950 Bytes
/
Copy pathProgram.cs
File metadata and controls
26 lines (20 loc) · 950 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
var config = new ConfigurationBuilder().AddUserSecrets<Program>().Build();
var endpoint = config["AzureOpenAI:Endpoint"] ?? throw new InvalidOperationException(
"Missing 'AzureOpenAI:Endpoint'. Run: dotnet user-secrets set \"AzureOpenAI:Endpoint\" \"https://<your-resource>.openai.azure.com/\"");
var deploymentName = config["AzureOpenAI:Deployment"] ?? "gpt-5-mini";
IChatClient chatClient =
new AzureOpenAIClient(
new Uri(endpoint),
new AzureCliCredential())
.GetChatClient(deploymentName)
.AsIChatClient();
AIAgent writer = chatClient.AsAIAgent(
name: "Writer",
instructions: "Write stories that are engaging and creative.");
AgentResponse response = await writer.RunAsync("Write a short story about a haunted house.");
Console.WriteLine(response.Text);