-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathChatClientProvider.cs
More file actions
33 lines (28 loc) · 925 Bytes
/
ChatClientProvider.cs
File metadata and controls
33 lines (28 loc) · 925 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
27
28
29
30
31
32
33
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
namespace MAF_BackgroundResponses_01_Simple;
class ChatClientProvider
{
public static IChatClient GetChatClient()
{
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());
return azureClient
.GetChatClient(deploymentName)
.AsIChatClient()
.AsBuilder()
.UseFunctionInvocation()
.Build();
}
}