-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathResponseClientProvider.cs
More file actions
32 lines (27 loc) · 1.05 KB
/
ResponseClientProvider.cs
File metadata and controls
32 lines (27 loc) · 1.05 KB
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
27
28
29
30
31
32
#pragma warning disable OPENAI001
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.AI;
using OpenAI.Responses;
namespace MAF_BackgroundResponses_01_Simple;
class ResponseClientProvider
{
// Return an IChatClient constructed from the AzureOpenAIClient so samples can create agents
public static IChatClient GetResponseClient()
{
var builder = Host.CreateApplicationBuilder();
var config = builder.Configuration
.AddEnvironmentVariables()
.AddUserSecrets<Program>()
.Build();
var deploymentName = config["AzureOpenAI:Deployment"] ?? "gpt-5-mini";
var endpoint = config["AzureOpenAI:Endpoint"];
var azureClient = new AzureOpenAIClient(
new Uri(endpoint),
new AzureCliCredential());
// Create a Chat client for the target deployment and return the IChatClient wrapper
return azureClient.GetChatClient(deploymentName).AsIChatClient();
}
}