Add OpenAIKeyProvider + RealtimeSettings record
This commit is contained in:
@@ -34,6 +34,7 @@ builder.Services.AddScoped<backend.Devices.DeviceTokenService>();
|
|||||||
builder.Services.AddScoped<backend.Pairing.PairingService>();
|
builder.Services.AddScoped<backend.Pairing.PairingService>();
|
||||||
builder.Services.AddSingleton<backend.Install.InstallScriptBuilder>();
|
builder.Services.AddSingleton<backend.Install.InstallScriptBuilder>();
|
||||||
builder.Services.AddScoped<backend.Conversations.ConversationLog>();
|
builder.Services.AddScoped<backend.Conversations.ConversationLog>();
|
||||||
|
builder.Services.AddSingleton<backend.Realtime.OpenAIKeyProvider>();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
namespace backend.Realtime;
|
||||||
|
|
||||||
|
public class OpenAIKeyProvider
|
||||||
|
{
|
||||||
|
private readonly string? _key;
|
||||||
|
|
||||||
|
public OpenAIKeyProvider(IConfiguration cfg)
|
||||||
|
{
|
||||||
|
_key = cfg["OPENAI_API_KEY"] ?? cfg["OpenAI:ApiKey"];
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool HasKey => !string.IsNullOrWhiteSpace(_key);
|
||||||
|
|
||||||
|
public string GetRequired()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(_key))
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"OPENAI_API_KEY is not configured. Set the env var on the Coolify app.");
|
||||||
|
return _key!;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
namespace backend.Realtime;
|
||||||
|
|
||||||
|
public record RealtimeSettings(
|
||||||
|
string Model,
|
||||||
|
string Voice,
|
||||||
|
string SystemPrompt,
|
||||||
|
int IdleTimeoutSeconds,
|
||||||
|
IReadOnlySet<string> EnabledTools);
|
||||||
Reference in New Issue
Block a user