Skip to content

Commit

Permalink
Merge pull request #363 from deepgram/feat/nova-3
Browse files Browse the repository at this point in the history
feat: support nova 3 and keyterms
  • Loading branch information
naomi-lgbt authored Feb 11, 2025
2 parents 393a5c8 + 90e95dd commit 9c75aaf
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 7 deletions.
5 changes: 5 additions & 0 deletions Deepgram/Clients/Agent/v2/Websocket/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -51,6 +52,10 @@ public Client(string? apiKey = null, IDeepgramClientOptions? options = null) : b
public async Task<bool> Connect(SettingsConfigurationSchema options, CancellationTokenSource? cancelToken = null, Dictionary<string, string>? addons = null,
Dictionary<string, string>? 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}");
Expand Down
5 changes: 5 additions & 0 deletions Deepgram/Clients/Listen/v2/WebSocket/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -49,6 +50,10 @@ public Client(string? apiKey = null, IDeepgramClientOptions? options = null) : b
public async Task<bool> Connect(LiveSchema options, CancellationTokenSource? cancelToken = null, Dictionary<string, string>? addons = null,
Dictionary<string, string>? 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}");
Expand Down
6 changes: 5 additions & 1 deletion Deepgram/Models/Agent/v2/WebSocket/Listen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 List<string>? Keyterms { get; set; }

/// <summary>
/// Override ToString method to serialize the object
Expand Down
8 changes: 8 additions & 0 deletions Deepgram/Models/Listen/v1/REST/PreRecordedSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ public class PreRecordedSchema
[JsonPropertyName("keywords")]
public List<string>? Keywords { get; set; }

/// <summary>
/// Keyterm Prompting allows you improve Keyword Recall Rate (KRR) for important keyterms or phrases up to 90%.
/// <see href="https://developers.deepgram.com/docs/keyterm">
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("keyterms")]
public List<string>? Keyterms { get; set; }

/// <summary>
/// Primary spoken language of submitted audio
/// <see href="https://developers.deepgram.com/docs/language">
Expand Down
8 changes: 8 additions & 0 deletions Deepgram/Models/Listen/v2/WebSocket/LiveSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ public class LiveSchema
[JsonPropertyName("keywords")]
public List<string>? Keywords { get; set; }

/// <summary>
/// Keyterm Prompting allows you improve Keyword Recall Rate (KRR) for important keyterms or phrases up to 90%.
/// <see href="https://developers.deepgram.com/docs/keyterm">
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("keyterms")]
public List<string>? Keyterms { get; set; }

/// <summary>
/// Primary spoken language of submitted audio
/// <see href="https://developers.deepgram.com/docs/language">
Expand Down
3 changes: 3 additions & 0 deletions examples/agent/websocket/simple/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Deepgram.Microphone;
using Deepgram.Models.Authenticate.v1;
using Deepgram.Models.Agent.v2.WebSocket;
using System.Collections.Generic;

namespace SampleApp
{
Expand Down Expand Up @@ -194,6 +195,8 @@ await agentClient.Subscribe(new EventHandler<ErrorResponse>((sender, e) =>
settingsConfiguration.Audio.Input.SampleRate = 44100;
settingsConfiguration.Context.Messages = new List<object> {};
settingsConfiguration.Context.Replay = false;
settingsConfiguration.Agent.Listen.Model = "nova-3";
settingsConfiguration.Agent.Listen.Keyterms = new List<string> { "Deepgram" };

bool bConnected = await agentClient.Connect(settingsConfiguration);
if (!bConnected)
Expand Down
4 changes: 3 additions & 1 deletion examples/speech-to-text/rest/file/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using Deepgram.Logger;
using Deepgram.Models.Listen.v1.REST;
using System.Collections.Generic;

namespace PreRecorded
{
Expand Down Expand Up @@ -36,7 +37,8 @@ static async Task Main(string[] args)
audioData,
new PreRecordedSchema()
{
Model = "nova-2",
Model = "nova-3",
Keyterms = new List<string> { "Bueller" },
Punctuate = true,
},
cancelToken);
Expand Down
4 changes: 3 additions & 1 deletion examples/speech-to-text/rest/intent/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT

using Deepgram.Models.Listen.v1.REST;
using System.Collections.Generic;

namespace PreRecorded
{
Expand All @@ -29,7 +30,8 @@ static async Task Main(string[] args)
audioData,
new PreRecordedSchema()
{
Model = "nova-2",
Model = "nova-3",
Keyterms = new List<string> { "Call Center" },
Punctuate = true,
Intents = true,
});
Expand Down
4 changes: 3 additions & 1 deletion examples/speech-to-text/rest/sentiment/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT

using Deepgram.Models.Listen.v1.REST;
using System.Collections.Generic;

namespace PreRecorded
{
Expand All @@ -29,7 +30,8 @@ static async Task Main(string[] args)
audioData,
new PreRecordedSchema()
{
Model = "nova-2",
Model = "nova-3",
Keyterms = new List<string> { "Call Center" },
Punctuate = true,
Utterances = true,
Sentiment = true,
Expand Down
4 changes: 3 additions & 1 deletion examples/speech-to-text/rest/summary/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT

using Deepgram.Models.Listen.v1.REST;
using System.Collections.Generic;

namespace PreRecorded
{
Expand All @@ -29,7 +30,8 @@ static async Task Main(string[] args)
audioData,
new PreRecordedSchema()
{
Model = "nova-2",
Model = "nova-3",
Keyterms = new List<string> { "Call Center" },
Punctuate = true,
Summarize = "v2",
});
Expand Down
4 changes: 3 additions & 1 deletion examples/speech-to-text/rest/topic/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT

using Deepgram.Models.Listen.v1.REST;
using System.Collections.Generic;

namespace PreRecorded
{
Expand All @@ -29,7 +30,8 @@ static async Task Main(string[] args)
audioData,
new PreRecordedSchema()
{
Model = "nova-2",
Model = "nova-3",
Keyterms = new List<string> { "Call Center" },
Punctuate = true,
Topics = true,
});
Expand Down
4 changes: 3 additions & 1 deletion examples/speech-to-text/rest/url/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: MIT

using Deepgram.Models.Listen.v1.REST;
using System.Collections.Generic;

namespace PreRecorded
{
Expand All @@ -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<string> { "Bueller" },
},
null, // use the default timeout
customOptions);
Expand Down

0 comments on commit 9c75aaf

Please sign in to comment.