-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
Extensions.cs
44 lines (36 loc) · 1.98 KB
/
Extensions.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
using eShop.Catalog.API.Services;
using Microsoft.SemanticKernel;
public static class Extensions
{
public static void AddApplicationServices(this IHostApplicationBuilder builder)
{
builder.AddNpgsqlDbContext<CatalogContext>("catalogdb", configureDbContextOptions: dbContextOptionsBuilder =>
{
dbContextOptionsBuilder.UseNpgsql(builder =>
{
builder.UseVector();
});
});
// REVIEW: This is done for development ease but shouldn't be here in production
builder.Services.AddMigration<CatalogContext, CatalogContextSeed>();
// Add the integration services that consume the DbContext
builder.Services.AddTransient<IIntegrationEventLogService, IntegrationEventLogService<CatalogContext>>();
builder.Services.AddTransient<ICatalogIntegrationEventService, CatalogIntegrationEventService>();
builder.AddRabbitMqEventBus("eventbus")
.AddSubscription<OrderStatusChangedToAwaitingValidationIntegrationEvent, OrderStatusChangedToAwaitingValidationIntegrationEventHandler>()
.AddSubscription<OrderStatusChangedToPaidIntegrationEvent, OrderStatusChangedToPaidIntegrationEventHandler>();
builder.Services.AddOptions<CatalogOptions>()
.BindConfiguration(nameof(CatalogOptions));
if (builder.Configuration["AI:Onnx:EmbeddingModelPath"] is string modelPath &&
builder.Configuration["AI:Onnx:EmbeddingVocabPath"] is string vocabPath)
{
builder.Services.AddBertOnnxTextEmbeddingGeneration(modelPath, vocabPath);
}
else if (!string.IsNullOrWhiteSpace(builder.Configuration.GetConnectionString("openai")))
{
builder.AddAzureOpenAIClient("openai");
builder.Services.AddOpenAITextEmbeddingGeneration(builder.Configuration["AIOptions:OpenAI:EmbeddingName"] ?? "text-embedding-3-small");
}
builder.Services.AddSingleton<ICatalogAI, CatalogAI>();
}
}