Merge pull request #1007 from iceljc/features/debug-local-realtime

Features/debug local realtime
This commit is contained in:
iceljc 2025-04-11 17:04:59 -05:00 committed by GitHub
commit c52e749e70
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 16 additions and 8 deletions

View file

@ -4,7 +4,7 @@ namespace BotSharp.Abstraction.Realtime;
public interface IRealtimeHook public interface IRealtimeHook
{ {
Task OnModeReady(Agent agent, IRealTimeCompletion completer); Task OnModelReady(Agent agent, IRealTimeCompletion completer);
string[] OnModelTranscriptPrompt(Agent agent); string[] OnModelTranscriptPrompt(Agent agent);
Task OnTranscribeCompleted(RoleDialogModel message, TranscriptionData data); Task OnTranscribeCompleted(RoleDialogModel message, TranscriptionData data);
} }

View file

@ -58,8 +58,7 @@ public class RealtimeHub : IRealtimeHub
var instruction = await _completer.UpdateSession(_conn); var instruction = await _completer.UpdateSession(_conn);
var data = _conn.OnModelReady(); var data = _conn.OnModelReady();
await responseToUser(data); await responseToUser(data);
await HookEmitter.Emit<IRealtimeHook>(_services, async hook => await hook.OnModeReady(agent, _completer)); await HookEmitter.Emit<IRealtimeHook>(_services, async hook => await hook.OnModelReady(agent, _completer));
}, },
onModelAudioDeltaReceived: async (audioDeltaData, itemId) => onModelAudioDeltaReceived: async (audioDeltaData, itemId) =>
{ {

View file

@ -4,21 +4,28 @@ using BotSharp.Core.Plugins;
using BotSharp.Logger; using BotSharp.Logger;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using System.Reflection;
namespace BotSharp.OpenAPI; namespace BotSharp.OpenAPI;
public class ServiceBuilder public class ServiceBuilder
{ {
public static IServiceProvider CreateHostBuilder() public static IServiceProvider CreateHostBuilder(Assembly? startUp = null)
{ {
Console.WriteLine("Creating host builder..."); Console.WriteLine("Creating host builder...");
// Set up configuration // Set up configuration
var configuration = new ConfigurationBuilder() var configurationBuilder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory()) .SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables() .AddEnvironmentVariables();
.Build();
if (startUp != null)
{
configurationBuilder.AddUserSecrets(startUp);
}
var configuration = configurationBuilder.Build();
// Create host builder // Create host builder
var builder = Host.CreateDefaultBuilder() var builder = Host.CreateDefaultBuilder()

View file

@ -5,6 +5,7 @@
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<UserSecretsId>d7da3ed7-20a7-4acc-8018-ef9b705fea40</UserSecretsId>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View file

@ -3,8 +3,9 @@ using BotSharp.Abstraction.Conversations.Models;
using BotSharp.Abstraction.Conversations; using BotSharp.Abstraction.Conversations;
using BotSharp.OpenAPI; using BotSharp.OpenAPI;
using System.Text.Json; using System.Text.Json;
using System.Reflection;
var services = ServiceBuilder.CreateHostBuilder(); var services = ServiceBuilder.CreateHostBuilder(Assembly.GetExecutingAssembly());
var channel = services.GetRequiredService<IStreamChannel>(); var channel = services.GetRequiredService<IStreamChannel>();
Console.WriteLine("PCM-16 Microphone Capture (24kHz Sample Rate)"); Console.WriteLine("PCM-16 Microphone Capture (24kHz Sample Rate)");