-
Notifications
You must be signed in to change notification settings - Fork 122
/
Program.cs
85 lines (75 loc) · 2.96 KB
/
Program.cs
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System.Text.Json;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Enums;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using Microsoft.SemanticKernel;
namespace KernelHttpServer;
public static class Program
{
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureAppConfiguration(configuration =>
{
var config = configuration.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true);
var builtConfig = config.Build();
})
.ConfigureServices(services =>
{
services.AddSingleton<IOpenApiConfigurationOptions>(_ => s_apiConfigOptions);
services.AddTransient((provider) => CreateKernel(provider));
// return JSON with expected lowercase naming
services.Configure<JsonSerializerOptions>(options =>
{
options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
});
})
.Build();
host.Run();
}
private static IKernel CreateKernel(IServiceProvider provider)
{
var kernelSettings = KernelSettings.LoadSettings();
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder
.SetMinimumLevel(kernelSettings.LogLevel ?? LogLevel.Warning)
.AddConsole()
.AddDebug();
});
return new KernelBuilder()
.WithLogger(loggerFactory.CreateLogger<IKernel>())
.WithCompletionService(kernelSettings)
.Build();
}
private static readonly OpenApiConfigurationOptions s_apiConfigOptions = new()
{
Info = new OpenApiInfo()
{
Version = "1.0.0",
Title = "Semantic Kernel Azure Functions Starter",
Description = "Azure Functions starter application for the [Semantic Kernel](https://github.com/microsoft/semantic-kernel).",
Contact = new OpenApiContact()
{
Name = "Issues",
Url = new Uri("https://github.com/microsoft/semantic-kernel-starters/issues"),
},
License = new OpenApiLicense()
{
Name = "MIT",
Url = new Uri("https://github.com/microsoft/semantic-kernel-starters/blob/main/LICENSE"),
}
},
Servers = DefaultOpenApiConfigurationOptions.GetHostNames(),
OpenApiVersion = OpenApiVersionType.V2,
ForceHttps = false,
ForceHttp = false,
};
}