38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
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>());
|
|
}
|
|
}
|