-
Notifications
You must be signed in to change notification settings - Fork 320
/
Program.cs
129 lines (108 loc) · 6.64 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright (c) Microsoft. All rights reserved.
using Aspire.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.KernelMemory;
using Microsoft.KernelMemory.Aspire;
using Projects;
internal static class Program
{
private const string QdrantImage = "qdrant/qdrant";
private const string KMDockerImage = "kernelmemory/service";
private static readonly AzureOpenAIConfig s_azureOpenAIEmbeddingConfig = new();
private static readonly AzureOpenAIConfig s_azureOpenAITextConfig = new();
private static readonly OpenAIConfig s_openAIConfig = new();
internal static void Main()
{
new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddJsonFile("appsettings.development.json", optional: true)
.AddJsonFile("appsettings.Development.json", optional: true)
.Build()
.BindSection("KernelMemory:Services:OpenAI", s_openAIConfig)
.BindSection("KernelMemory:Services:AzureOpenAIEmbedding", s_azureOpenAIEmbeddingConfig)
.BindSection("KernelMemory:Services:AzureOpenAIText", s_azureOpenAITextConfig);
RunFromCode();
// RunFromDockerWithOpenAI(s_openAIConfig.APIKey);
// RunFromDockerImage("latest");
// RunFromDockerImage("latest-arm64");
}
private static void RunFromCode()
{
var builder = DistributedApplication.CreateBuilder();
var qdrant = builder.AddContainer("qdrant", QdrantImage)
.WithHttpEndpoint(targetPort: 6333)
.PublishAsContainer();
// Find Qdrant endpoint and pass the value to KM below
var qdrantEndpoint = qdrant.GetEndpoint("http");
builder.AddProject<Service>("kernel-memory")
// Wait for Qdrant to be ready
.WaitFor(qdrant)
// Global KM settings
.WithEnvironment("KernelMemory__TextGeneratorType", "AzureOpenAIText")
.WithEnvironment("KernelMemory__DataIngestion__EmbeddingGeneratorTypes__0", "AzureOpenAIEmbedding")
.WithEnvironment("KernelMemory__DataIngestion__MemoryDbTypes__0", "Qdrant")
.WithEnvironment("KernelMemory__Retrieval__EmbeddingGeneratorType", "AzureOpenAIEmbedding")
.WithEnvironment("KernelMemory__Retrieval__MemoryDbType", "Qdrant")
// Qdrant settings
.WithEnvironment("KernelMemory__Services__Qdrant__Endpoint", qdrantEndpoint)
.WithEnvironment("KernelMemory__Services__Qdrant__APIKey", "")
// Azure OpenAI settings - Text generation
.WithEnvironment("KernelMemory__Services__AzureOpenAIText__Auth", s_azureOpenAITextConfig.Auth.ToString("G"))
.WithEnvironment("KernelMemory__Services__AzureOpenAIText__APIKey", s_azureOpenAITextConfig.APIKey)
.WithEnvironment("KernelMemory__Services__AzureOpenAIText__Endpoint", s_azureOpenAITextConfig.Endpoint)
.WithEnvironment("KernelMemory__Services__AzureOpenAIText__Deployment", s_azureOpenAITextConfig.Deployment)
// Azure OpenAI settings - Embeddings
.WithEnvironment("KernelMemory__Services__AzureOpenAIEmbedding__Auth", s_azureOpenAIEmbeddingConfig.Auth.ToString("G"))
.WithEnvironment("KernelMemory__Services__AzureOpenAIEmbedding__APIKey", s_azureOpenAIEmbeddingConfig.APIKey)
.WithEnvironment("KernelMemory__Services__AzureOpenAIEmbedding__Endpoint", s_azureOpenAIEmbeddingConfig.Endpoint)
.WithEnvironment("KernelMemory__Services__AzureOpenAIEmbedding__Deployment", s_azureOpenAIEmbeddingConfig.Deployment);
builder
.ShowDashboardUrl()
.LaunchDashboard()
.Build().Run();
}
private static void RunFromDockerWithOpenAI(string openAIKey, string dockerTag = "latest")
{
var builder = DistributedApplication.CreateBuilder();
builder.AddContainer("kernel-memory", KMDockerImage, tag: dockerTag)
.WithEnvironment("KernelMemory__TextGeneratorType", "OpenAI")
.WithEnvironment("KernelMemory__DataIngestion__EmbeddingGeneratorTypes__0", "OpenAI")
.WithEnvironment("KernelMemory__Retrieval__EmbeddingGeneratorType", "OpenAI")
.WithEnvironment("KernelMemory__Services__OpenAI__APIKey", openAIKey);
builder.Build().Run();
}
private static void RunFromDockerImage(string dockerTag = "latest")
{
var builder = DistributedApplication.CreateBuilder();
var qdrant = builder.AddContainer("qdrant", QdrantImage)
.WithHttpEndpoint(targetPort: 6333)
.PublishAsContainer();
// Find Qdrant endpoint and pass the value to KM below
var qdrantEndpoint = qdrant.GetEndpoint("http");
builder.AddContainer("kernel-memory", KMDockerImage, tag: dockerTag)
.WithHttpEndpoint(targetPort: 9001)
// Wait for Qdrant to be ready
.WaitFor(qdrant)
// Global KM settings
.WithEnvironment("KernelMemory__TextGeneratorType", "AzureOpenAIText")
.WithEnvironment("KernelMemory__DataIngestion__EmbeddingGeneratorTypes__0", "AzureOpenAIEmbedding")
.WithEnvironment("KernelMemory__DataIngestion__MemoryDbTypes__0", "Qdrant")
.WithEnvironment("KernelMemory__Retrieval__EmbeddingGeneratorType", "AzureOpenAIEmbedding")
.WithEnvironment("KernelMemory__Retrieval__MemoryDbType", "Qdrant")
// Qdrant settings
.WithEnvironment("KernelMemory__Services__Qdrant__Endpoint", qdrantEndpoint)
.WithEnvironment("KernelMemory__Services__Qdrant__APIKey", "")
// Azure OpenAI settings - Text generation
.WithEnvironment("KernelMemory__Services__AzureOpenAIText__Auth", s_azureOpenAITextConfig.Auth.ToString("G"))
.WithEnvironment("KernelMemory__Services__AzureOpenAIText__APIKey", s_azureOpenAITextConfig.APIKey)
.WithEnvironment("KernelMemory__Services__AzureOpenAIText__Endpoint", s_azureOpenAITextConfig.Endpoint)
.WithEnvironment("KernelMemory__Services__AzureOpenAIText__Deployment", s_azureOpenAITextConfig.Deployment)
// Azure OpenAI settings - Embeddings
.WithEnvironment("KernelMemory__Services__AzureOpenAIEmbedding__Auth", s_azureOpenAIEmbeddingConfig.Auth.ToString("G"))
.WithEnvironment("KernelMemory__Services__AzureOpenAIEmbedding__APIKey", s_azureOpenAIEmbeddingConfig.APIKey)
.WithEnvironment("KernelMemory__Services__AzureOpenAIEmbedding__Endpoint", s_azureOpenAIEmbeddingConfig.Endpoint)
.WithEnvironment("KernelMemory__Services__AzureOpenAIEmbedding__Deployment", s_azureOpenAIEmbeddingConfig.Deployment)
.PublishAsContainer();
builder.Build().Run();
}
}