refactor SemanticKernelTextEmbeddingProvider
This commit is contained in:
parent
fe3e324fb8
commit
eccef74d47
|
|
@ -20,6 +20,7 @@ namespace BotSharp.Plugin.SemanticKernel
|
|||
/// <inheritdoc/>
|
||||
public void RegisterDI(IServiceCollection services, IConfiguration config)
|
||||
{
|
||||
|
||||
var provider = services.BuildServiceProvider().CreateScope().ServiceProvider;
|
||||
|
||||
if (provider.GetService<Microsoft.SemanticKernel.AI.TextCompletion.ITextCompletion>() != null)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using BotSharp.Abstraction.MLTasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.SemanticKernel;
|
||||
using Microsoft.SemanticKernel.AI.Embeddings;
|
||||
using Microsoft.SemanticKernel.Memory;
|
||||
|
|
@ -17,17 +18,20 @@ namespace BotSharp.Plugin.SemanticKernel
|
|||
public class SemanticKernelTextEmbeddingProvider : ITextEmbedding
|
||||
{
|
||||
private readonly ITextEmbeddingGeneration _embedding;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Constructor of <see cref="SemanticKernelTextEmbeddingProvider"/>
|
||||
/// </summary>
|
||||
public SemanticKernelTextEmbeddingProvider(ITextEmbeddingGeneration embedding)
|
||||
public SemanticKernelTextEmbeddingProvider(ITextEmbeddingGeneration embedding, IConfiguration configuration)
|
||||
{
|
||||
this._embedding = embedding;
|
||||
this._configuration = configuration;
|
||||
this.Dimension = configuration.GetValue<int>("SemanticKernel:Dimension");
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public int Dimension { get; }
|
||||
public int Dimension { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public async Task<float[]> GetVectorAsync(string text)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ namespace BotSharp.Plugin.SemanticKernel.Tests
|
|||
{
|
||||
var services = new ServiceCollection();
|
||||
var config = new ConfigurationBuilder().Build();
|
||||
|
||||
services.AddSingleton<IConfiguration>(config);
|
||||
|
||||
var plugin = new SemanticKernelPlugin();
|
||||
services.AddScoped(x => Mock.Of<Microsoft.SemanticKernel.AI.TextCompletion.ITextCompletion>());
|
||||
services.AddScoped(x => Mock.Of<Microsoft.SemanticKernel.AI.ChatCompletion.IChatCompletion>());
|
||||
|
|
|
|||
Loading…
Reference in a new issue