-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathServiceDependencies.cs
More file actions
76 lines (67 loc) · 3.87 KB
/
ServiceDependencies.cs
File metadata and controls
76 lines (67 loc) · 3.87 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
69
70
71
72
73
74
75
76
using Microsoft.GS.DPSHost.API;
using Microsoft.KernelMemory;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.ChatCompletion;
using Microsoft.Extensions.Options;
using Microsoft.GS.DPS.API;
using Microsoft.GS.DPS.Storage.ChatSessions;
using Microsoft.GS.DPS.Storage.Document;
using MongoDB.Driver;
using FluentValidation;
using Microsoft.GS.DPS.Model.UserInterface;
using Microsoft.GS.DPS.Storage.AISearch;
using Microsoft.GS.DPSHost.AppConfiguration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.GS.DPSHost.Helpers;
namespace Microsoft.GS.DPSHost.ServiceConfiguration
{
public class ServiceDependencies
{
public static void Inject(IHostApplicationBuilder builder)
{
builder.Services
.AddValidatorsFromAssemblyContaining<PagingRequestValidator>()
.AddSingleton<Microsoft.GS.DPS.API.KernelMemory>()
.AddSingleton<Microsoft.GS.DPS.API.ChatHost>()
.AddSingleton<Microsoft.GS.DPS.API.UserInterface.Documents>()
.AddSingleton<Microsoft.GS.DPS.API.UserInterface.DataCacheManager>()
.AddSingleton<Microsoft.SemanticKernel.Kernel>(x =>
{
return Kernel.CreateBuilder()
.AddAzureOpenAIChatCompletion(deploymentName: builder.Configuration.GetSection("Application:AIServices:GPT-4o-mini")["ModelName"] ?? "",
endpoint: builder.Configuration.GetSection("Application:AIServices:GPT-4o-mini")["Endpoint"] ?? "",
credentials: AzureCredentialHelper.GetAzureCredential())
.Build();
})
.AddSingleton<ChatSessionRepository>(x =>
{
var services = x.GetRequiredService<IOptions<Services>>().Value;
return new ChatSessionRepository(
new MongoClient(services.PersistentStorage.CosmosMongo.ConnectionString ?? "")
.GetDatabase(services.PersistentStorage.CosmosMongo.Collections.ChatHistory.Database ?? ""),
collectionName: services.PersistentStorage.CosmosMongo.Collections.ChatHistory.Collection ?? ""
);
})
.AddSingleton<DocumentRepository>(x =>
{
var services = x.GetRequiredService<IOptions<Services>>().Value;
return new DocumentRepository(
new MongoClient(services.PersistentStorage.CosmosMongo.ConnectionString ?? "")
.GetDatabase(services.PersistentStorage.CosmosMongo.Collections.DocumentManager.Database ?? ""),
collectionName: services.PersistentStorage.CosmosMongo.Collections.DocumentManager.Collection ?? ""
);
})
.AddSingleton<MemoryWebClient>(x =>
{
var services = x.GetRequiredService<IOptions<Services>>().Value;
return new MemoryWebClient(endpoint: services.KernelMemory.Endpoint ?? "", new HttpClient() { Timeout = new TimeSpan(0, 60, 0) });
})
.AddSingleton<TagUpdater>(x =>
{
var services = x.GetRequiredService<IOptions<Services>>().Value;
return new TagUpdater(services.AzureAISearch.Endpoint, AzureCredentialHelper.GetAzureCredential());
})
;
}
}
}