From ed0c9dee5812e354ce640c50e98cfd81df6e51a7 Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Thu, 6 Feb 2025 14:43:31 -0800 Subject: [PATCH 1/4] feat: support nova 3 in agent --- Deepgram/Models/Agent/v2/WebSocket/Listen.cs | 6 +++++- examples/agent/websocket/simple/Program.cs | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Deepgram/Models/Agent/v2/WebSocket/Listen.cs b/Deepgram/Models/Agent/v2/WebSocket/Listen.cs index 26e461e2..c3bedfe6 100644 --- a/Deepgram/Models/Agent/v2/WebSocket/Listen.cs +++ b/Deepgram/Models/Agent/v2/WebSocket/Listen.cs @@ -8,7 +8,11 @@ public record Listen { [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("model")] - public string Model { get; set; } = "nova-2"; + public string Model { get; set; } + + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("keyterms")] + public string[] Keyterms { get; set; } /// /// Override ToString method to serialize the object diff --git a/examples/agent/websocket/simple/Program.cs b/examples/agent/websocket/simple/Program.cs index d7e9787b..35eb68c6 100644 --- a/examples/agent/websocket/simple/Program.cs +++ b/examples/agent/websocket/simple/Program.cs @@ -194,6 +194,8 @@ await agentClient.Subscribe(new EventHandler((sender, e) => settingsConfiguration.Audio.Input.SampleRate = 44100; settingsConfiguration.Context.Messages = new List {}; settingsConfiguration.Context.Replay = false; + settingsConfiguration.Agent.Listen.Model = "nova-3"; + settingsConfiguration.Agent.Listen.Keyterms = new string[] { "Deepgram" }; bool bConnected = await agentClient.Connect(settingsConfiguration); if (!bConnected) From 26ec3070b62a9c7e2f3b784a324b7f699635597c Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Thu, 6 Feb 2025 14:58:12 -0800 Subject: [PATCH 2/4] feat: support nova-3 and keyterms in listen --- Deepgram/Models/Listen/v1/REST/PreRecordedSchema.cs | 8 ++++++++ Deepgram/Models/Listen/v2/WebSocket/LiveSchema.cs | 8 ++++++++ examples/speech-to-text/rest/file/Program.cs | 4 +++- examples/speech-to-text/rest/intent/Program.cs | 4 +++- examples/speech-to-text/rest/sentiment/Program.cs | 4 +++- examples/speech-to-text/rest/summary/Program.cs | 4 +++- examples/speech-to-text/rest/topic/Program.cs | 4 +++- examples/speech-to-text/rest/url/Program.cs | 4 +++- 8 files changed, 34 insertions(+), 6 deletions(-) diff --git a/Deepgram/Models/Listen/v1/REST/PreRecordedSchema.cs b/Deepgram/Models/Listen/v1/REST/PreRecordedSchema.cs index d235f827..d0d9d154 100644 --- a/Deepgram/Models/Listen/v1/REST/PreRecordedSchema.cs +++ b/Deepgram/Models/Listen/v1/REST/PreRecordedSchema.cs @@ -148,6 +148,14 @@ public class PreRecordedSchema [JsonPropertyName("keywords")] public List? Keywords { get; set; } + /// + /// Keyterm Prompting allows you improve Keyword Recall Rate (KRR) for important keyterms or phrases up to 90%. + /// + /// + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("keyterms")] + public List? Keyterms { get; set; } + /// /// Primary spoken language of submitted audio /// diff --git a/Deepgram/Models/Listen/v2/WebSocket/LiveSchema.cs b/Deepgram/Models/Listen/v2/WebSocket/LiveSchema.cs index a36dcea7..cab733fc 100644 --- a/Deepgram/Models/Listen/v2/WebSocket/LiveSchema.cs +++ b/Deepgram/Models/Listen/v2/WebSocket/LiveSchema.cs @@ -117,6 +117,14 @@ public class LiveSchema [JsonPropertyName("keywords")] public List? Keywords { get; set; } + /// + /// Keyterm Prompting allows you improve Keyword Recall Rate (KRR) for important keyterms or phrases up to 90%. + /// + /// + [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] + [JsonPropertyName("keyterms")] + public List? Keyterms { get; set; } + /// /// Primary spoken language of submitted audio /// diff --git a/examples/speech-to-text/rest/file/Program.cs b/examples/speech-to-text/rest/file/Program.cs index 2a0da3e2..93f89eff 100644 --- a/examples/speech-to-text/rest/file/Program.cs +++ b/examples/speech-to-text/rest/file/Program.cs @@ -4,6 +4,7 @@ using Deepgram.Logger; using Deepgram.Models.Listen.v1.REST; +using System.Collections.Generic; namespace PreRecorded { @@ -36,7 +37,8 @@ static async Task Main(string[] args) audioData, new PreRecordedSchema() { - Model = "nova-2", + Model = "nova-3", + Keyterms = new List { "Bueller" }, Punctuate = true, }, cancelToken); diff --git a/examples/speech-to-text/rest/intent/Program.cs b/examples/speech-to-text/rest/intent/Program.cs index 37b16021..dfa0a4ac 100644 --- a/examples/speech-to-text/rest/intent/Program.cs +++ b/examples/speech-to-text/rest/intent/Program.cs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MIT using Deepgram.Models.Listen.v1.REST; +using System.Collections.Generic; namespace PreRecorded { @@ -29,7 +30,8 @@ static async Task Main(string[] args) audioData, new PreRecordedSchema() { - Model = "nova-2", + Model = "nova-3", + Keyterms = new List { "Call Center" }, Punctuate = true, Intents = true, }); diff --git a/examples/speech-to-text/rest/sentiment/Program.cs b/examples/speech-to-text/rest/sentiment/Program.cs index 489685a5..603ae6f4 100644 --- a/examples/speech-to-text/rest/sentiment/Program.cs +++ b/examples/speech-to-text/rest/sentiment/Program.cs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MIT using Deepgram.Models.Listen.v1.REST; +using System.Collections.Generic; namespace PreRecorded { @@ -29,7 +30,8 @@ static async Task Main(string[] args) audioData, new PreRecordedSchema() { - Model = "nova-2", + Model = "nova-3", + Keyterms = new List { "Call Center" }, Punctuate = true, Utterances = true, Sentiment = true, diff --git a/examples/speech-to-text/rest/summary/Program.cs b/examples/speech-to-text/rest/summary/Program.cs index 66d6549b..4024e8c0 100644 --- a/examples/speech-to-text/rest/summary/Program.cs +++ b/examples/speech-to-text/rest/summary/Program.cs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MIT using Deepgram.Models.Listen.v1.REST; +using System.Collections.Generic; namespace PreRecorded { @@ -29,7 +30,8 @@ static async Task Main(string[] args) audioData, new PreRecordedSchema() { - Model = "nova-2", + Model = "nova-3", + Keyterms = new List { "Call Center" }, Punctuate = true, Summarize = "v2", }); diff --git a/examples/speech-to-text/rest/topic/Program.cs b/examples/speech-to-text/rest/topic/Program.cs index 8db27637..660e8f6d 100644 --- a/examples/speech-to-text/rest/topic/Program.cs +++ b/examples/speech-to-text/rest/topic/Program.cs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MIT using Deepgram.Models.Listen.v1.REST; +using System.Collections.Generic; namespace PreRecorded { @@ -29,7 +30,8 @@ static async Task Main(string[] args) audioData, new PreRecordedSchema() { - Model = "nova-2", + Model = "nova-3", + Keyterms = new List { "Call Center" }, Punctuate = true, Topics = true, }); diff --git a/examples/speech-to-text/rest/url/Program.cs b/examples/speech-to-text/rest/url/Program.cs index 36098205..62bbde2f 100644 --- a/examples/speech-to-text/rest/url/Program.cs +++ b/examples/speech-to-text/rest/url/Program.cs @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MIT using Deepgram.Models.Listen.v1.REST; +using System.Collections.Generic; namespace PreRecorded { @@ -25,7 +26,8 @@ static async Task Main(string[] args) new UrlSource("https://dpgr.am/bueller.wav"), new PreRecordedSchema() { - Model = "nova-2", + Model = "nova-3", + Keyterms = new List { "Bueller" }, }, null, // use the default timeout customOptions); From 80bd4cd79c68b73d0026b73ee2622f4ea3e3bbb4 Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Thu, 6 Feb 2025 14:59:35 -0800 Subject: [PATCH 3/4] fix: agent keyterms should use list for parity with rest of sdk --- Deepgram/Models/Agent/v2/WebSocket/Listen.cs | 2 +- examples/agent/websocket/simple/Program.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Deepgram/Models/Agent/v2/WebSocket/Listen.cs b/Deepgram/Models/Agent/v2/WebSocket/Listen.cs index c3bedfe6..2f26293e 100644 --- a/Deepgram/Models/Agent/v2/WebSocket/Listen.cs +++ b/Deepgram/Models/Agent/v2/WebSocket/Listen.cs @@ -12,7 +12,7 @@ public record Listen [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] [JsonPropertyName("keyterms")] - public string[] Keyterms { get; set; } + public List? Keyterms { get; set; } /// /// Override ToString method to serialize the object diff --git a/examples/agent/websocket/simple/Program.cs b/examples/agent/websocket/simple/Program.cs index 35eb68c6..823e9e67 100644 --- a/examples/agent/websocket/simple/Program.cs +++ b/examples/agent/websocket/simple/Program.cs @@ -6,6 +6,7 @@ using Deepgram.Microphone; using Deepgram.Models.Authenticate.v1; using Deepgram.Models.Agent.v2.WebSocket; +using System.Collections.Generic; namespace SampleApp { @@ -195,7 +196,7 @@ await agentClient.Subscribe(new EventHandler((sender, e) => settingsConfiguration.Context.Messages = new List {}; settingsConfiguration.Context.Replay = false; settingsConfiguration.Agent.Listen.Model = "nova-3"; - settingsConfiguration.Agent.Listen.Keyterms = new string[] { "Deepgram" }; + settingsConfiguration.Agent.Listen.Keyterms = new List { "Deepgram" }; bool bConnected = await agentClient.Connect(settingsConfiguration); if (!bConnected) From 90e95dd934c32cdaca6b96bede7b9335213b47e0 Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Thu, 6 Feb 2025 15:19:11 -0800 Subject: [PATCH 4/4] feat: error on keyterms when not nova-3 --- Deepgram/Clients/Agent/v2/Websocket/Client.cs | 5 +++++ Deepgram/Clients/Listen/v2/WebSocket/Client.cs | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/Deepgram/Clients/Agent/v2/Websocket/Client.cs b/Deepgram/Clients/Agent/v2/Websocket/Client.cs index 39b3ac2a..1ee16057 100644 --- a/Deepgram/Clients/Agent/v2/Websocket/Client.cs +++ b/Deepgram/Clients/Agent/v2/Websocket/Client.cs @@ -7,6 +7,7 @@ using Deepgram.Models.Agent.v2.WebSocket; using Common = Deepgram.Models.Common.v2.WebSocket; using Deepgram.Clients.Interfaces.v2; +using Deepgram.Models.Exceptions.v1; namespace Deepgram.Clients.Agent.v2.WebSocket; @@ -51,6 +52,10 @@ public Client(string? apiKey = null, IDeepgramClientOptions? options = null) : b public async Task Connect(SettingsConfigurationSchema options, CancellationTokenSource? cancelToken = null, Dictionary? addons = null, Dictionary? headers = null) { + if (!options.Agent.Listen.Model.StartsWith("nova-3") && options.Agent.Listen.Keyterms?.Count > 0) + { + throw new DeepgramException("Keyterms is only supported in Nova 3 models."); + } Log.Verbose("AgentWSClient.Connect", "ENTER"); Log.Information("Connect", $"options:\n{JsonSerializer.Serialize(options, JsonSerializeOptions.DefaultOptions)}"); Log.Debug("Connect", $"addons: {addons}"); diff --git a/Deepgram/Clients/Listen/v2/WebSocket/Client.cs b/Deepgram/Clients/Listen/v2/WebSocket/Client.cs index ad93626b..e06a31e1 100644 --- a/Deepgram/Clients/Listen/v2/WebSocket/Client.cs +++ b/Deepgram/Clients/Listen/v2/WebSocket/Client.cs @@ -8,6 +8,7 @@ using Deepgram.Models.Listen.v2.WebSocket; using Common = Deepgram.Models.Common.v2.WebSocket; using Deepgram.Clients.Interfaces.v2; +using Deepgram.Models.Exceptions.v1; namespace Deepgram.Clients.Listen.v2.WebSocket; @@ -49,6 +50,10 @@ public Client(string? apiKey = null, IDeepgramClientOptions? options = null) : b public async Task Connect(LiveSchema options, CancellationTokenSource? cancelToken = null, Dictionary? addons = null, Dictionary? headers = null) { + if (!options.Model.StartsWith("nova-3") && options.Keyterms?.Count > 0) + { + throw new DeepgramException("Keyterms is only supported in Nova 3 models."); + } Log.Verbose("ListenWSClient.Connect", "ENTER"); Log.Information("Connect", $"options:\n{JsonSerializer.Serialize(options, JsonSerializeOptions.DefaultOptions)}"); Log.Debug("Connect", $"addons: {addons}");