refactor semantic kernel Plugin
This commit is contained in:
parent
eb1b77904b
commit
fe3e324fb8
|
|
@ -21,10 +21,9 @@ namespace BotSharp.Plugin.SemanticKernel
|
|||
/// <summary>
|
||||
/// Constructor of <see cref="SemanticKernelTextEmbeddingProvider"/>
|
||||
/// </summary>
|
||||
public SemanticKernelTextEmbeddingProvider(ITextEmbeddingGeneration embedding, int dimension)
|
||||
public SemanticKernelTextEmbeddingProvider(ITextEmbeddingGeneration embedding)
|
||||
{
|
||||
this._embedding = embedding;
|
||||
Dimension = dimension;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ namespace BotSharp.Plugin.SemanticKernel.Tests
|
|||
_chatCompletionMock = new Mock<Microsoft.SemanticKernel.AI.ChatCompletion.IChatCompletion>();
|
||||
_servicesMock = new Mock<IServiceProvider>();
|
||||
_tokenStatisticsMock = new Mock<ITokenStatistics>();
|
||||
_provider = new SemanticKernelChatCompletionProvider(_chatCompletionMock, _servicesMock.Object, _tokenStatisticsMock.Object);
|
||||
_provider = new SemanticKernelChatCompletionProvider(_chatCompletionMock.Object, _servicesMock.Object, _tokenStatisticsMock.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -55,15 +55,13 @@ namespace BotSharp.Plugin.SemanticKernel.Tests
|
|||
.Returns(agentService.Object);
|
||||
|
||||
var chatHistoryMock = new Mock<ChatHistory>();
|
||||
var chatCompletionMock = new Mock<Microsoft.SemanticKernel.AI.ChatCompletion.IChatCompletion>();
|
||||
chatCompletionMock.Setup(x => x.CreateNewChat(It.IsAny<string>())).Returns(chatHistoryMock.Object);
|
||||
chatCompletionMock.Setup(x => x.GetChatCompletionsAsync(chatHistoryMock.Object, It.IsAny<AIRequestSettings>(), It.IsAny<CancellationToken>()))
|
||||
_chatCompletionMock.Setup(x => x.CreateNewChat(It.IsAny<string>())).Returns(chatHistoryMock.Object);
|
||||
_chatCompletionMock.Setup(x => x.GetChatCompletionsAsync(chatHistoryMock.Object, It.IsAny<AIRequestSettings>(), It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new List<IChatResult>
|
||||
{
|
||||
new ResultHelper("How can I help you?")
|
||||
});
|
||||
|
||||
_kernelMock.Setup(x => x.GetService<Microsoft.SemanticKernel.AI.ChatCompletion.IChatCompletion>(null)).Returns(chatCompletionMock.Object);
|
||||
|
||||
// Act
|
||||
var result = _provider.GetChatCompletions(agent, conversations);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
using BotSharp.Abstraction.Conversations;
|
||||
using BotSharp.Abstraction.MLTasks;
|
||||
using BotSharp.Abstraction.VectorStorage;
|
||||
using BotSharp.Plugin.SemanticKernel.UnitTests.Helpers;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.SemanticKernel;
|
||||
|
|
@ -15,21 +17,21 @@ namespace BotSharp.Plugin.SemanticKernel.Tests
|
|||
var services = new ServiceCollection();
|
||||
var config = new ConfigurationBuilder().Build();
|
||||
var plugin = new SemanticKernelPlugin();
|
||||
services.AddScoped(x =>
|
||||
{
|
||||
return new KernelBuilder()
|
||||
.WithAzureOpenAIChatCompletionService("test", "test", "test")
|
||||
.Build();
|
||||
});
|
||||
services.AddScoped<ITokenStatistics>(x=> Mock.Of<ITokenStatistics>());
|
||||
services.AddScoped(x => Mock.Of<Microsoft.SemanticKernel.AI.TextCompletion.ITextCompletion>());
|
||||
services.AddScoped(x => Mock.Of<Microsoft.SemanticKernel.AI.ChatCompletion.IChatCompletion>());
|
||||
services.AddScoped(x => Mock.Of<Microsoft.SemanticKernel.Memory.IMemoryStore>());
|
||||
services.AddScoped(x => Mock.Of<Microsoft.SemanticKernel.AI.Embeddings.ITextEmbeddingGeneration>());
|
||||
services.AddScoped(x => Mock.Of<ITokenStatistics>());
|
||||
|
||||
|
||||
plugin.RegisterDI(services, config);
|
||||
|
||||
var provider = services.BuildServiceProvider();
|
||||
var provider = services.BuildServiceProvider().CreateScope().ServiceProvider;
|
||||
|
||||
Assert.NotNull(provider.GetService<ITextCompletion>());
|
||||
Assert.NotNull(provider.GetService<IChatCompletion>());
|
||||
Assert.NotNull(provider.GetService<IVectorDb>());
|
||||
Assert.NotNull(provider.GetService<ITextEmbedding>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -37,10 +37,7 @@ namespace BotSharp.Plugin.SemanticKernel.Tests
|
|||
|
||||
var text = "Hello";
|
||||
var expected = "Hello, world!";
|
||||
var _kernel = new KernelBuilder()
|
||||
.WithAIService<ITextCompletion>("", new SemanticKernelHelper(expected))
|
||||
.Build();
|
||||
var provider = new SemanticKernelTextCompletionProvider(_kernel, _services, _tokenStatistics);
|
||||
var provider = new SemanticKernelTextCompletionProvider(new SemanticKernelHelper(expected), _services, _tokenStatistics);
|
||||
|
||||
// Act
|
||||
var result = await provider.GetCompletion(text, "agent1", "message1");
|
||||
|
|
|
|||
Loading…
Reference in a new issue