-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigExtensions.cs
44 lines (40 loc) · 1.78 KB
/
ConfigExtensions.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 Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Memory;
public static class ConfigExtensions
{
public static IKernel Configure(this KernelBuilder kernelBuilder, Config? embeddingConfig, Config? completionConfig)
{
if (embeddingConfig != null)
{
switch (embeddingConfig.AIService.ToUpperInvariant())
{
case Config.AzureOpenAI:
kernelBuilder = kernelBuilder.WithAzureTextEmbeddingGenerationService(embeddingConfig.DeploymentOrModelId, embeddingConfig.Endpoint, embeddingConfig.Key);
break;
case Config.OpenAI:
kernelBuilder = kernelBuilder.WithOpenAITextEmbeddingGenerationService(embeddingConfig.DeploymentOrModelId, embeddingConfig.Key);
break;
default:
throw new NotSupportedException("Invalid AI Service was specified for embeddings");
}
}
if (completionConfig != null)
{
switch (completionConfig.AIService.ToUpperInvariant())
{
case Config.AzureOpenAI:
kernelBuilder = kernelBuilder.WithAzureChatCompletionService(completionConfig.DeploymentOrModelId, completionConfig.Endpoint, completionConfig.Key);
break;
case Config.OpenAI:
kernelBuilder = kernelBuilder.WithOpenAIChatCompletionService(completionConfig.DeploymentOrModelId, completionConfig.Key);
break;
default:
throw new NotSupportedException("Invalid AI Service was specified for completions");
}
}
return kernelBuilder.
WithMemoryStorage(new VolatileMemoryStore()).
Build();
}
}