-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
69 lines (57 loc) · 2.79 KB
/
Program.cs
File metadata and controls
69 lines (57 loc) · 2.79 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
59
60
61
62
63
64
65
66
67
68
using api_process_runner.Interfaces;
using api_process_runner.Plugins;
using api_process_runner.Services;
using api_process_runner.Util;
using Azure.Search.Documents.Indexes;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
//
string _apiDeploymentName = Helper.GetEnvironmentVariable("ApiDeploymentName");
string _apiEndpoint = Helper.GetEnvironmentVariable("ApiEndpoint");
string _apiKey = Helper.GetEnvironmentVariable("ApiKey");
string _apiAISearchEndpoint = Helper.GetEnvironmentVariable("AISearchURL");
string _apiAISearchKey = Helper.GetEnvironmentVariable("AISearchKey");
string _textEmbeddingName = Helper.GetEnvironmentVariable("EmbeddingName");
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
services.AddTransient<Kernel>(s =>
{
var builder = Kernel.CreateBuilder();
builder.AddAzureOpenAIChatCompletion(
_apiDeploymentName,
_apiEndpoint,
_apiKey
);
builder.Services.AddSingleton<SearchIndexClient>(s =>
{
string endpoint = _apiAISearchEndpoint;
string apiKey = _apiAISearchKey;
return new SearchIndexClient(new Uri(endpoint), new Azure.AzureKeyCredential(apiKey));
});
// Add Singleton for AzureAISearch
builder.Services.AddSingleton<IAzureAISearchService, AzureAISearchService>();
#pragma warning disable SKEXP0011 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
builder.AddAzureOpenAITextEmbeddingGeneration(_textEmbeddingName, _apiEndpoint, _apiKey);
#pragma warning restore SKEXP0011 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
builder.Plugins.AddFromType<AzureAISearchPlugin>();
return builder.Build();
});
services.AddSingleton<IChatCompletionService>(sp =>
sp.GetRequiredService<Kernel>().GetRequiredService<IChatCompletionService>());
const string systemmsg = @$"You are a friendly assistant that can use Semantic Kernal Plugins and extract details from files to take action against";
services.AddSingleton<ChatHistory>(s =>
{
var chathistory = new ChatHistory();
chathistory.AddSystemMessage(systemmsg);
return chathistory;
});
})
.Build();
host.Run();