Add OpenAIRealtimeUpstream + RealtimeSessionFactory + DI registrations
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
using backend.Conversations;
|
||||
using backend.Tools;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace backend.Realtime;
|
||||
|
||||
public class RealtimeSessionFactory
|
||||
{
|
||||
protected readonly OpenAIKeyProvider keys;
|
||||
protected readonly ToolRegistry registry;
|
||||
protected readonly ConversationLog log;
|
||||
protected readonly ILoggerFactory loggerFactory;
|
||||
|
||||
public RealtimeSessionFactory(
|
||||
OpenAIKeyProvider keys, ToolRegistry registry,
|
||||
ConversationLog log, ILoggerFactory loggerFactory)
|
||||
{
|
||||
this.keys = keys;
|
||||
this.registry = registry;
|
||||
this.log = log;
|
||||
this.loggerFactory = loggerFactory;
|
||||
}
|
||||
|
||||
public virtual async Task<RealtimeSession> CreateAsync(
|
||||
Guid deviceId,
|
||||
RealtimeSettings cfg,
|
||||
ISessionOutput output,
|
||||
IDeviceChannel channel,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var upstream = new OpenAIRealtimeUpstream();
|
||||
await upstream.ConnectAsync(keys.GetRequired(), cfg.Model, ct);
|
||||
return new RealtimeSession(
|
||||
deviceId, upstream, output, log, registry, cfg, channel,
|
||||
loggerFactory.CreateLogger<RealtimeSession>());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user