-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram.cs
More file actions
58 lines (46 loc) · 1.83 KB
/
Program.cs
File metadata and controls
58 lines (46 loc) · 1.83 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Azure.AI.OpenAI;
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.Docs;
using Microsoft.Extensions.AI;
using OpenAI.Chat;
using System.Text.Json.Serialization;
string openAIApiKey = Environment.GetEnvironmentVariable("AZURE_OPENAI_KEY");
string openAIEndpoint = Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT");
string openAIModel = Environment.GetEnvironmentVariable("AZURE_OPENAI_MODEL_NAME");
var builder = WebApplication.CreateBuilder(args);
// Create an Azure OpenAI client with endpoint and API key from helper.
var azureOpenAIClient = new AzureOpenAIClient(
new Uri(openAIEndpoint),
new System.ClientModel.ApiKeyCredential(openAIApiKey));
// Get a model-specific chat client and adapt it to IChatClient.
IChatClient chatClient = azureOpenAIClient
.GetChatClient(openAIModel)
.AsIChatClient();
// Register the chat client as a singleton in the dependency injection container.
builder.Services.AddSingleton(chatClient);
builder.Services.AddChatClient(chatClient);
// Add DevExpress AI services and register the document-processing extensions.
builder.Services.AddDevExpressAIConsole((config) => {
config.RegisterAIDocProcessingService();
});
// Add services to the container.
builder.Services.AddControllers().AddJsonOptions(options => {
/*
.. Other config
*/
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
});
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment()) {
app.UseSwagger();
app.UseSwaggerUI();
//app.DescribeAllEnumsAsStrings();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();