BotSharp/src/Plugins/BotSharp.Plugin.SemanticKernel/SemanticKernelPlugin.cs

46 lines
1.6 KiB
C#
Raw Normal View History

2023-11-12 09:12:34 +00:00
using BotSharp.Abstraction.MLTasks;
using BotSharp.Abstraction.Plugins;
using BotSharp.Abstraction.VectorStorage;
2023-11-12 09:12:34 +00:00
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace BotSharp.Plugin.SemanticKernel
{
2023-11-19 13:34:13 +00:00
/// <summary>
/// Use Semantic Kernel as BotSharp plugin
/// </summary>
2023-11-12 09:12:34 +00:00
public class SemanticKernelPlugin : IBotSharpPlugin
{
2023-11-19 13:34:13 +00:00
/// <inheritdoc/>
2023-11-12 09:12:34 +00:00
public string Name => "Semantic Kernel";
2023-11-19 13:34:13 +00:00
/// <inheritdoc/>
2023-11-12 09:12:34 +00:00
public string Description => "Semantic Kernel Service";
2023-11-12 14:04:00 +00:00
2023-11-19 13:34:13 +00:00
/// <inheritdoc/>
2023-11-12 09:12:34 +00:00
public void RegisterDI(IServiceCollection services, IConfiguration config)
{
2023-11-19 13:34:13 +00:00
var provider = services.BuildServiceProvider().CreateScope().ServiceProvider;
if (provider.GetService<Microsoft.SemanticKernel.AI.TextCompletion.ITextCompletion>() != null)
{
services.AddScoped<ITextCompletion, SemanticKernelTextCompletionProvider>();
}
if (provider.GetService<Microsoft.SemanticKernel.AI.ChatCompletion.IChatCompletion>() != null)
{
services.AddScoped<IChatCompletion, SemanticKernelChatCompletionProvider>();
}
if (provider.GetService<Microsoft.SemanticKernel.Memory.IMemoryStore>() != null)
{
services.AddScoped<IVectorDb, SemanticKernelMemoryStoreProvider>();
}
2023-11-19 13:34:13 +00:00
if (provider.GetService<Microsoft.SemanticKernel.AI.Embeddings.ITextEmbeddingGeneration>() != null)
{
services.AddScoped<ITextEmbedding, SemanticKernelTextEmbeddingProvider>();
}
2023-11-12 09:12:34 +00:00
}
}
2023-11-12 14:04:00 +00:00
}