Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support nova 3 and keyterms #363

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was debating if we needed this exception in the SDKs as our API enforcing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed in Slack - moot point, we're fine either way as these SDKs will soon be approached differently.

}
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 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 Expand Up @@ -619,7 +624,7 @@

if (_deepgramClientOptions.AutoFlushReplyDelta > 0)
{
if ((bool)resultResponse.IsFinal)

Check warning on line 627 in Deepgram/Clients/Listen/v2/WebSocket/Client.cs

View workflow job for this annotation

GitHub Actions / test (8.0.x)

Nullable value type may be null.
{
var now = DateTime.Now;
Log.Debug("InspectMessage", $"AutoFlush IsFinal received. Time: {now}");
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
Loading