BotSharp/tests/BotSharp.LLM.Tests/GoogleRealTimeTests.cs
2025-05-19 15:44:20 -05:00

61 lines
2.3 KiB
C#

using BotSharp.Abstraction.Agents.Enums;
using BotSharp.Abstraction.Agents.Models;
using BotSharp.Abstraction.Conversations.Models;
using BotSharp.Abstraction.MLTasks;
using BotSharp.Abstraction.Realtime.Models;
using GenerativeAI;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
namespace BotSharp.Plugin.Google.Core
{
public class GoogleRealTimeTests : TestBase
{
protected static Agent CreateTestAgent()
{
return new Agent()
{
Id = "test-agent-id",
Name = "TestAgent",
Description = "This is a test agent used for unit testing purposes.",
Type = "Chat",
CreatedDateTime = DateTime.UtcNow,
UpdatedDateTime = DateTime.UtcNow,
IsPublic = false,
Disabled = false
};
}
[Fact]
public async Task ShouldConnect_Tests()
{
if (!LLMProvider.CanRunGemini)
return;
(IServiceCollection services, IConfiguration config, string modelName) = LLMProvider.CreateGemini();
var agent = CreateTestAgent();
var realTimeCompleter = services.BuildServiceProvider().GetService<IRealTimeCompletion>();
realTimeCompleter.SetModelName(GoogleAIModels.Gemini2FlashExp);
bool modelReady = false;
await realTimeCompleter.Connect(
new RealtimeHubConnection(),
async () => { modelReady = true; },
async (s, s1) => { Console.WriteLine(s); },
async () => { },
async (s) => { Console.WriteLine(s); },
async list => { Console.WriteLine(list); },
async s => { Console.WriteLine(s); },
async model => { Console.WriteLine(model); },
async () => { Console.WriteLine("UserInterrupted"); });
Thread.Sleep(1000);
modelReady.ShouldBeTrue();
await realTimeCompleter.InsertConversationItem(new RoleDialogModel(AgentRole.User,
"tell me something about Albert Einstein."));
Thread.Sleep(10000);
}
}
}