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

Implement Models API #322

Merged
merged 1 commit into from
Aug 14, 2024
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
10 changes: 10 additions & 0 deletions Deepgram.Dev.sln
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Speak", "examples\text-to-s
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Speak", "examples\text-to-speech\rest\file\woodchuck\Speak.csproj", "{12115887-AFBF-4EEF-953D-936B9D810E97}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "models", "models", "{1CC0C0DE-55D9-4B83-9070-1668A4472A27}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Models", "examples\manage\models\Models.csproj", "{918E56D3-FABF-4F50-AC01-8DDFF58FB0CE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -285,6 +289,10 @@ Global
{12115887-AFBF-4EEF-953D-936B9D810E97}.Debug|Any CPU.Build.0 = Debug|Any CPU
{12115887-AFBF-4EEF-953D-936B9D810E97}.Release|Any CPU.ActiveCfg = Release|Any CPU
{12115887-AFBF-4EEF-953D-936B9D810E97}.Release|Any CPU.Build.0 = Release|Any CPU
{918E56D3-FABF-4F50-AC01-8DDFF58FB0CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{918E56D3-FABF-4F50-AC01-8DDFF58FB0CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{918E56D3-FABF-4F50-AC01-8DDFF58FB0CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{918E56D3-FABF-4F50-AC01-8DDFF58FB0CE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -359,6 +367,8 @@ Global
{E1B8DE3D-2B86-4A60-BDC1-A7F425986DC1} = {F2DCE1E6-FC12-4CA5-A738-5A3F359B8A96}
{1850D8CC-ADFD-4187-80D4-C5DBDA55B6E3} = {F31817AD-AC9F-4021-A9E0-7C26C31D5744}
{12115887-AFBF-4EEF-953D-936B9D810E97} = {E1B8DE3D-2B86-4A60-BDC1-A7F425986DC1}
{1CC0C0DE-55D9-4B83-9070-1668A4472A27} = {FA5723B3-74E9-4221-80EF-4833C1C3DD9F}
{918E56D3-FABF-4F50-AC01-8DDFF58FB0CE} = {1CC0C0DE-55D9-4B83-9070-1668A4472A27}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {8D4ABC6D-7126-4EE2-9303-43A954616B2A}
Expand Down
2 changes: 1 addition & 1 deletion Deepgram/ClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static IListenWebSocketClient CreateListenWebSocketClient(string apiKey =
}

/// <summary>
/// Create a new LiveClient
/// Create a new ManageClient
/// </summary>
/// <param name="apiKey"></param>
/// <param name="options"></param>
Expand Down
34 changes: 34 additions & 0 deletions Deepgram/Clients/Interfaces/v1/IManageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,40 @@ public Task<MessageResponse> DeleteProject(string projectId, CancellationTokenSo
/// <returns><see cref="MessageResponse"/></returns>
public Task<MessageResponse> LeaveProject(string projectId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Get all models associated with the project Id
/// </summary>
/// <param name="projectId">Id of project</param>
/// <returns><see cref="ModelsResponse"/></returns>
public Task<ModelsResponse> GetProjectModels(string projectId, ModelSchema? modelSchema = null, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Get a specific model associated with the project Id
/// </summary>
/// <param name="projectId">Id of project</param>
/// <param name="modelId">Id of model</param>
/// <returns><see cref="ModelResponse"/></returns>
public Task<ModelResponse> GetProjectModel(string projectId, string modelId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);
#endregion

#region Models
/// <summary>
/// Gets models available in Deepgram
/// </summary>
/// <returns><see cref="ModelsResponse"/></returns>
public Task<ModelsResponse> GetModels(ModelSchema? modelSchema = null, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);

/// <summary>
/// Gets a specific model within Deepgram
/// </summary>
/// <param name="projectId">Id of Model</param>
/// <returns><see cref="ModelResponse"/></returns>
public Task<ModelResponse> GetModel(string modelId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null);
#endregion

#region ProjectKeys
Expand Down
97 changes: 95 additions & 2 deletions Deepgram/Clients/Manage/v1/Client.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

Expand All @@ -9,7 +9,7 @@
namespace Deepgram.Clients.Manage.v1;

/// <summary>
/// Implements version 1 of the Manage Client.
/// Implements version 1 of the Models Client.
/// </summary>
/// <param name="apiKey">Required DeepgramApiKey</param>
/// <param name="deepgramClientOptions"><see cref="DeepgramHttpClientOptions"/> for HttpClient Configuration</param>
Expand Down Expand Up @@ -122,6 +122,99 @@ public async Task<MessageResponse> LeaveProject(string projectId, CancellationTo

return result;
}

/// <summary>
/// Gets projects associated to ApiKey
/// </summary>
/// <returns><see cref="ModelsResponse"/></returns>
public async Task<ModelsResponse> GetProjectModels(string projectId, ModelSchema? modelSchema = null, CancellationTokenSource ? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null)
{
Log.Verbose("ManageClient.GetProjectModels", "ENTER");

if (modelSchema is null)
{
modelSchema = new ModelSchema();
}

var uri = GetUri(_options, $"{UriSegments.PROJECTS}/{projectId}/{UriSegments.MODELS}");
var result = await GetAsync<ModelSchema, ModelsResponse>(uri, modelSchema, cancellationToken, addons, headers);

Log.Information("GetProjectModels", $"{uri} Succeeded");
Log.Debug("GetProjectModels", $"result: {result}");
Log.Verbose("ManageClient.GetProjectModels", "LEAVE");

return result;
}

/// <summary>
/// Gets project associated with project Id
/// </summary>
/// <param name="projectId">Id of Project</param>
/// <returns><see cref="ModelResponse"/></returns>
public async Task<ModelResponse> GetProjectModel(string projectId, string modelId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null)
{
Log.Verbose("ManageClient.GetProjectModel", "ENTER");
Log.Information("ProjectId", $"projectId: {projectId}");
Log.Information("ModelId", $"modelId: {modelId}");

var uri = GetUri(_options, $"{UriSegments.PROJECTS}/{projectId}/{UriSegments.MODELS}/{modelId}");
var result = await GetAsync<ModelResponse>(uri, cancellationToken, addons, headers);

Log.Information("GetProjectModel", $"{uri} Succeeded");
Log.Debug("GetProjectModel", $"result: {result}");
Log.Verbose("ManageClient.GetProjectModel", "LEAVE");

return result;
}
#endregion

#region Models
/// <summary>
/// Gets models available in Deepgram
/// </summary>
/// <returns><see cref="ModelsResponse"/></returns>
public async Task<ModelsResponse> GetModels(ModelSchema? modelSchema = null, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null)
{
Log.Verbose("ManageClient.GetModels", "ENTER");

if (modelSchema is null)
{
modelSchema = new ModelSchema();
}

var uri = GetUri(_options, $"{UriSegments.MODELS}");
var result = await GetAsync<ModelSchema, ModelsResponse>(uri, modelSchema, cancellationToken, addons, headers);

Log.Information("GetModels", $"{uri} Succeeded");
Log.Debug("GetModels", $"result: {result}");
Log.Verbose("ManageClient.GetModels", "LEAVE");

return result;
}

/// <summary>
/// Gets a specific model within Deepgram
/// </summary>
/// <param name="projectId">Id of Model</param>
/// <returns><see cref="ModelResponse"/></returns>
public async Task<ModelResponse> GetModel(string modelId, CancellationTokenSource? cancellationToken = default,
Dictionary<string, string>? addons = null, Dictionary<string, string>? headers = null)
{
Log.Verbose("ManageClient.GetModel", "ENTER");
Log.Information("ModelID", $"modelId: {modelId}");

var uri = GetUri(_options, $"{UriSegments.MODELS}/{modelId}");
var result = await GetAsync<ModelResponse>(uri, cancellationToken, addons, headers);

Log.Information("GetModel", $"{uri} Succeeded");
Log.Debug("GetModel", $"result: {result}");
Log.Verbose("ManageClient.GetModel", "LEAVE");

return result;
}
#endregion

#region ProjectKeys
Expand Down
3 changes: 2 additions & 1 deletion Deepgram/Clients/Manage/v1/UriSegments.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

Expand All @@ -17,4 +17,5 @@ public static class UriSegments
public const string SCOPES = "scopes";
public const string REQUESTS = "requests";
public const string LISTEN = "listen";
public const string MODELS = "models";
}
1 change: 0 additions & 1 deletion Deepgram/Models/Manage/v1/KeySchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace Deepgram.Models.Manage.v1;

public class KeySchema
{

/// <summary>
/// Comment to describe key
/// </summary>
Expand Down
43 changes: 43 additions & 0 deletions Deepgram/Models/Manage/v1/Metadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Manage.v1;

public record Metadata
{
/// <summary>
/// Contains the accent value
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("accent")]
public string? Accent { get; set; }

/// <summary>
/// Contains the color value
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("color")]
public string? Color { get; set; }

/// <summary>
/// Contains the image value
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("image")]
public Uri? Image { get; set; }

/// <summary>
/// Contains the sample value
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("sample")]
public Uri? Sample { get; set; }

/// <summary>
/// Tags or annotations for the model
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("tags")]
public List<string>? Tags { get; set; }
}
57 changes: 57 additions & 0 deletions Deepgram/Models/Manage/v1/ModelResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Manage.v1;

public record ModelResponse
{
/// <summary>
/// Name of the model
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("name")]
public string? Name { get; set; }

/// <summary>
/// Canonical name of the model
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("canonical_name")]
public string? CanonicalName { get; set; }

/// <summary>
/// Architecture of the model
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("architecture")]
public string? Architecture { get; set; }

/// <summary>
/// Lanugage of the model
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("language")]
public string? Language { get; set; }

/// <summary>
/// Version of the model
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("version")]
public string? Version { get; set; }

/// <summary>
/// UUID of the model
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("uuid")]
public string? Uuid { get; set; }

/// <summary>
/// Metadata of the model
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("metadata")]
public Metadata? Metadata { get; set; }
}
23 changes: 23 additions & 0 deletions Deepgram/Models/Manage/v1/ModelSchema.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Manage.v1;

public class ModelSchema
{
/// <summary>
/// Name of Project
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("include_outdated")]
public bool? IncludeOutdated { get; set; }

/// <summary>
/// Override ToString method to serialize the object
/// </summary>
public override string ToString()
{
return Regex.Unescape(JsonSerializer.Serialize(this, JsonSerializeOptions.DefaultOptions));
}
}
22 changes: 22 additions & 0 deletions Deepgram/Models/Manage/v1/ModelsResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2024 Deepgram .NET SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT

namespace Deepgram.Models.Manage.v1;

public record ModelsResponse
{
/// <summary>
/// Contains the Speech-to-Text models
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("stt")]
public List<Stt>? Stt { get; set; }

/// <summary>
/// Contains the Text-to-Speech models
/// </summary>
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
[JsonPropertyName("tts")]
public List<Tts>? Tts { get; set; }
}
Loading
Loading