BotSharp/tests/BotSharp.Plugin.SemanticKernel.UnitTests/SemanticKernelTextCompletionProviderTests.cs

54 lines
1.6 KiB
C#
Raw Normal View History

2023-11-12 14:04:00 +00:00
using BotSharp.Abstraction.Conversations.Models;
using BotSharp.Plugin.SemanticKernel;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.AI.TextCompletion;
using Moq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
using BotSharp.Abstraction.Agents.Enums;
using BotSharp.Abstraction.Agents.Models;
using BotSharp.Abstraction.Conversations;
using System;
using System.Linq;
using Microsoft;
using Microsoft.SemanticKernel.AI;
2023-11-13 15:11:49 +00:00
using BotSharp.Plugin.SemanticKernel.UnitTests.Helpers;
2023-11-12 14:04:00 +00:00
namespace BotSharp.Plugin.SemanticKernel.Tests
{
public class SemanticKernelTextCompletionProviderTests
{
private readonly IServiceProvider _services;
private readonly ITokenStatistics _tokenStatistics;
public SemanticKernelTextCompletionProviderTests()
{
2023-11-13 15:11:49 +00:00
2023-11-12 14:04:00 +00:00
_services = new ServiceCollection().BuildServiceProvider();
_tokenStatistics = Mock.Of<ITokenStatistics>();
}
[Fact]
public async Task GetCompletion_ReturnsExpectedResult()
{
// Arrange
2023-11-13 15:11:49 +00:00
2023-11-12 14:04:00 +00:00
var text = "Hello";
var expected = "Hello, world!";
2023-11-13 15:11:49 +00:00
var _kernel = new KernelBuilder()
.WithAIService<ITextCompletion>("", new SemanticKernelHelper(expected))
.Build();
var provider = new SemanticKernelTextCompletionProvider(_kernel, _services, _tokenStatistics);
2023-11-12 14:04:00 +00:00
// Act
2023-11-13 15:11:49 +00:00
var result = await provider.GetCompletion(text, "agent1", "message1");
2023-11-12 14:04:00 +00:00
// Assert
Assert.Equal(expected, result);
}
}
}