diff --git a/backend/Program.cs b/backend/Program.cs index 3c69ec4..cae286d 100644 --- a/backend/Program.cs +++ b/backend/Program.cs @@ -34,6 +34,7 @@ builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddScoped(); +builder.Services.AddSingleton(); var app = builder.Build(); diff --git a/backend/Realtime/OpenAIKeyProvider.cs b/backend/Realtime/OpenAIKeyProvider.cs new file mode 100644 index 0000000..51cc44e --- /dev/null +++ b/backend/Realtime/OpenAIKeyProvider.cs @@ -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!; + } +} diff --git a/backend/Realtime/RealtimeSettings.cs b/backend/Realtime/RealtimeSettings.cs new file mode 100644 index 0000000..808a5eb --- /dev/null +++ b/backend/Realtime/RealtimeSettings.cs @@ -0,0 +1,8 @@ +namespace backend.Realtime; + +public record RealtimeSettings( + string Model, + string Voice, + string SystemPrompt, + int IdleTimeoutSeconds, + IReadOnlySet EnabledTools);