-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathChatClientProvider.cs
More file actions
31 lines (26 loc) · 872 Bytes
/
ChatClientProvider.cs
File metadata and controls
31 lines (26 loc) · 872 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
using Azure.AI.OpenAI;
using Azure.Identity;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
namespace MAF_ImageGen_01;
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 client = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential())
.GetChatClient(deploymentName)
.AsIChatClient()
.AsBuilder()
.UseFunctionInvocation()
.Build();
return client;
}
}