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

🌿 Fern Regeneration -- August 1, 2024 #37

Merged
merged 11 commits into from
Aug 1, 2024
13 changes: 11 additions & 2 deletions .fernignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,29 @@

README.md
LICENSE.md
.gitignore
.github/workflows/ci.yml
src/AssemblyAI/AssemblyAI.csproj
src/AssemblyAI/Core/ClientOptions.cs
src/AssemblyAI/Core/JsonConfiguration.cs
src/AssemblyAI/ClientOptions.cs
src/AssemblyAI/Constants.cs
src/AssemblyAI/UserAgent.cs
src/AssemblyAI/Event.cs
src/AssemblyAI/AssemblyAIClient.cs
src/AssemblyAI/DependencyInjectionExtensions.cs
src/AssemblyAI/Files/FilesCustomClient.cs
src/AssemblyAI/Transcripts/TranscriptsCustomClient.cs
src/AssemblyAI/Files/ExtendedFilesClient.cs
src/AssemblyAI/Transcripts/ExtendedTranscriptsClient.cs
src/AssemblyAI/Lemur/Types/LemurResponse.cs
src/AssemblyAI/Realtime/RealtimeTranscriber.cs
src/AssemblyAI/Realtime/WebsocketClient
src/AssemblyAI/Realtime/Types/RealtimeTranscript.cs
src/AssemblyAI.Test
src/AssemblyAI.UnitTests
src/AssemblyAI.IntegrationTests

# TODO: remove these ignores when AssemblyAI fixes the API
src/AssemblyAI/Transcripts/Types/ContentSafetyLabelsResult.cs
src/AssemblyAI/Transcripts/Types/TopicDetectionModelResult.cs

Samples
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,32 @@ jobs:
- name: Build Release
run: dotnet build src -c Release /p:ContinuousIntegrationBuild=true

tests:
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- uses: actions/checkout@master

- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.x

- name: Install tools
run: |
dotnet tool restore

- name: Run Tests
run: |
dotnet test src
env:
ASSEMBLYAI_API_KEY: ${{ secrets.ASSEMBLYAI_API_KEY }}
TEST_TRANSCRIPT_ID: ${{ secrets.TEST_TRANSCRIPT_ID }}
TEST_TRANSCRIPT_IDS: ${{ secrets.TEST_TRANSCRIPT_IDS }}


publish:
needs: [compile]
Expand Down
15 changes: 9 additions & 6 deletions src/AssemblyAI.IntegrationTests/AssemblyAITestParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ internal static string ApiKey
{
get
{
var apiKey = TestContext.Parameters.Get("ASSEMBLYAI_API_KEY");
var apiKey = TestContext.Parameters.Get("ASSEMBLYAI_API_KEY")
?? Environment.GetEnvironmentVariable("ASSEMBLYAI_API_KEY");
if (string.IsNullOrEmpty(apiKey))
throw new Exception("ASSEMBLYAI_API_KEY .runsettings parameter is not set.");
throw new Exception("ASSEMBLYAI_API_KEY parameter is not set.");
return apiKey;
}
}
Expand All @@ -18,9 +19,10 @@ internal static string TranscriptId
{
get
{
var transcriptId = TestContext.Parameters.Get("TEST_TRANSCRIPT_ID");
var transcriptId = TestContext.Parameters.Get("TEST_TRANSCRIPT_ID")
?? Environment.GetEnvironmentVariable("TEST_TRANSCRIPT_ID");
if (string.IsNullOrEmpty(transcriptId))
throw new Exception("TEST_TRANSCRIPT_ID .runsettings parameter is not set.");
throw new Exception("TEST_TRANSCRIPT_ID parameter is not set.");
return transcriptId;
}
}
Expand All @@ -29,9 +31,10 @@ internal static string[] TranscriptIds
{
get
{
var transcriptIds = TestContext.Parameters.Get("TEST_TRANSCRIPT_IDS");
var transcriptIds = TestContext.Parameters.Get("TEST_TRANSCRIPT_IDS")
?? Environment.GetEnvironmentVariable("TEST_TRANSCRIPT_IDS");
if (string.IsNullOrEmpty(transcriptIds))
throw new Exception("TEST_TRANSCRIPT_IDS .runsettings parameter is not set.");
throw new Exception("TEST_TRANSCRIPT_IDS parameter is not set.");
return transcriptIds.Split(',');
}
}
Expand Down
29 changes: 25 additions & 4 deletions src/AssemblyAI.IntegrationTests/LemurTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using AssemblyAI.Lemur;

namespace AssemblyAI.IntegrationTests;

[TestFixture]
Expand All @@ -6,8 +8,7 @@ public class LemurTests
private static string ApiKey => AssemblyAITestParameters.ApiKey;
private static string[] TranscriptIds => AssemblyAITestParameters.TranscriptIds;

// TODO: uncomment when Fern fixes params generation
/*[Test]
[Test]
public async Task Should_Generate_Summary()
{
var client = new AssemblyAIClient(ApiKey);
Expand Down Expand Up @@ -105,9 +106,29 @@ public async Task Should_Return_Response()
}).ConfigureAwait(false);

var taskResponse2OneOf = await client.Lemur.GetResponseAsync(taskResponse.RequestId).ConfigureAwait(false);
var taskResponse2 = (LemurStringResponse) taskResponse2OneOf.Value;
var taskResponse2 = taskResponse2OneOf.AsT0;
Assert.That(taskResponse2.RequestId, Is.EqualTo(taskResponse.RequestId));
Assert.That(taskResponse2.Response, Is.EqualTo(taskResponse.Response));


var qaResponse = await client.Lemur.QuestionAnswerAsync(new LemurQuestionAnswerParams
{
FinalModel = LemurModel.Basic,
TranscriptIds = TranscriptIds,
Questions =
[
new LemurQuestion
{
Question = "What are they discussing?",
AnswerFormat = "text"
}
]
}).ConfigureAwait(false);

var qaResponse2OneOf = await client.Lemur.GetResponseAsync(qaResponse.RequestId).ConfigureAwait(false);
var qaResponse2 = qaResponse2OneOf.AsT1;
Assert.That(qaResponse2.RequestId, Is.EqualTo(qaResponse.RequestId));
Assert.That(qaResponse2.Response.Count(), Is.EqualTo(qaResponse.Response.Count()));
}

[Test]
Expand All @@ -124,5 +145,5 @@ public async Task Should_Purge_Request_Data()
var deletionRequest = await client.Lemur.PurgeRequestDataAsync(summaryResponse.RequestId).ConfigureAwait(false);
Assert.That(deletionRequest.Deleted, Is.True);
Assert.That(summaryResponse.RequestId, Is.EqualTo(deletionRequest.RequestIdToPurge));
}*/
}
}
2 changes: 2 additions & 0 deletions src/AssemblyAI.IntegrationTests/RealtimeClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using AssemblyAI.Realtime;

namespace AssemblyAI.IntegrationTests;

[TestFixture]
Expand Down
15 changes: 12 additions & 3 deletions src/AssemblyAI.IntegrationTests/TranscriptsClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using AssemblyAI.Transcripts;

namespace AssemblyAI.IntegrationTests;

[TestFixture]
Expand All @@ -20,6 +22,7 @@ public async Task Should_Submit_Using_Uri()

Assert.That(transcript, Is.Not.Null);
Assert.That(transcript.Id, Is.Not.Null);
Assert.That(transcript.Text, Is.Null);
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Queued));
}

Expand All @@ -36,6 +39,7 @@ public async Task Should_Submit_Using_Stream()

Assert.That(transcript, Is.Not.Null);
Assert.That(transcript.Id, Is.Not.Null);
Assert.That(transcript.Text, Is.Null);
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Queued));
}

Expand All @@ -52,6 +56,7 @@ public async Task Should_Submit_Using_FileInfo()

Assert.That(transcript, Is.Not.Null);
Assert.That(transcript.Id, Is.Not.Null);
Assert.That(transcript.Text, Is.Null);
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Queued));
}

Expand All @@ -66,7 +71,8 @@ public async Task Should_Transcribe_Using_Uri()

Assert.That(transcript, Is.Not.Null);
Assert.That(transcript.Id, Is.Not.Null);
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Queued));
Assert.That(transcript.Text, Is.Not.Empty);
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Completed));
}

[Test]
Expand All @@ -82,6 +88,7 @@ public async Task Should_Transcribe_From_FileInfo()

Assert.That(transcript, Is.Not.Null);
Assert.That(transcript.Id, Is.Not.Null);
Assert.That(transcript.Text, Is.Not.Empty);
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Completed));
}

Expand All @@ -98,6 +105,7 @@ public async Task Should_Transcribe_Using_Stream()

Assert.That(transcript, Is.Not.Null);
Assert.That(transcript.Id, Is.Not.Null);
Assert.That(transcript.Text, Is.Not.Empty);
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Completed));
}

Expand All @@ -111,7 +119,7 @@ public async Task Should_Fail_To_Transcribe()

Assert.That(transcript, Is.Not.Null);
Assert.That(transcript.Id, Is.Not.Null);
Assert.That(transcript.Text, Is.Empty);
Assert.That(transcript.Text, Is.Null);
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Error));
Assert.That(transcript.Error, Is.Not.Empty);
}
Expand All @@ -130,6 +138,7 @@ public async Task Should_Wait_Until_Ready()

Assert.That(transcript, Is.Not.Null);
Assert.That(transcript.Id, Is.Not.Null);
Assert.That(transcript.Text, Is.Not.Empty);
Assert.That(transcript.Status, Is.EqualTo(TranscriptStatus.Completed));
}

Expand Down Expand Up @@ -157,7 +166,7 @@ public async Task Should_Delete_Transcript()

Assert.That(transcript, Is.Not.Null);
Assert.That(transcript.Id, Is.Not.Null);
Assert.That(transcript.Text, Is.Empty);
Assert.That(transcript.Text, Is.EqualTo("Deleted by user."));
Assert.That(transcript.AudioUrl, Is.EqualTo("http://deleted_by_user"));
}

Expand Down
6 changes: 3 additions & 3 deletions src/AssemblyAI.UnitTests/DiClientOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class DependencyInjectionClientOptionsTests
ApiKey = "MyAssemblyAIApiKey",
BaseUrl = "https://api.assemblyai.com",
MaxRetries = 2,
TimeoutInSeconds = 30
Timeout = TimeSpan.FromSeconds(30)
};

[Test]
Expand All @@ -27,7 +27,7 @@ public void AddAssemblyAIClient_With_Callback_Should_Match_Configuration()
options.ApiKey = ValidAssemblyAIOptions.ApiKey;
options.BaseUrl = ValidAssemblyAIOptions.BaseUrl;
options.MaxRetries = ValidAssemblyAIOptions.MaxRetries;
options.TimeoutInSeconds = ValidAssemblyAIOptions.TimeoutInSeconds;
options.Timeout = ValidAssemblyAIOptions.Timeout;
});

var serviceProvider = serviceCollection.BuildServiceProvider();
Expand Down Expand Up @@ -62,7 +62,7 @@ public async Task AddAssemblyAIClient_From_Configuration_Should_Reload_On_Change
ApiKey = "UpdatedApiKey",
BaseUrl = "https://api.updated.assemblyai.com",
MaxRetries = 3,
TimeoutInSeconds = 45
Timeout = TimeSpan.FromSeconds(45)
};

jsonText = JsonSerializer.Serialize(new { AssemblyAI = updatedOptions });
Expand Down
5 changes: 5 additions & 0 deletions src/AssemblyAI/AssemblyAIClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
using System.Net.Http;
using AssemblyAI;
using AssemblyAI.Core;
using AssemblyAI.Files;
using AssemblyAI.Lemur;
using AssemblyAI.Realtime;
using AssemblyAI.Transcripts;


namespace AssemblyAI;
Expand All @@ -26,6 +30,7 @@ public AssemblyAIClient(ClientOptions clientOptions)
clientOptions.HttpClient ??= new HttpClient();
var client = new RawClient(
new Dictionary<string, string>(),
new Dictionary<string, Func<string>>(),
clientOptions
);
clientOptions.HttpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", clientOptions.ApiKey);
Expand Down
4 changes: 2 additions & 2 deletions src/AssemblyAI/ClientOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ClientOptions
/// <summary>
/// The Base URL for the API.
/// </summary>
public string BaseUrl { get; set; } = Environments.DEFAULT;
public string BaseUrl { get; set; } = AssemblyAIClientEnvironment.DEFAULT;

private UserAgent? _userAgent = UserAgent.Default;

Expand Down Expand Up @@ -49,5 +49,5 @@ public UserAgent? UserAgent
/// <summary>
/// The timeout for the request in seconds.
/// </summary>
public int TimeoutInSeconds { get; set; } = 30;
public TimeSpan Timeout { get; set; } = TimeSpan.FromSeconds(30);
}
27 changes: 27 additions & 0 deletions src/AssemblyAI/Core/AssemblyAIClientApiException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using AssemblyAI.Core;

#nullable enable

namespace AssemblyAI.Core;
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't want to expose a Core namespace, so let's put this at the root namespace.


/// <summary>
/// This exception type will be thrown for any non-2XX API responses.
/// </summary>
public class AssemblyAIClientApiException(string message, int statusCode, object body)
: AssemblyAIClientException(message)
{
/// <summary>
/// The error code of the response that triggered the exception.
/// </summary>
public int StatusCode { get; } = statusCode;

/// <summary>
/// The body of the response that triggered the exception.
/// </summary>
public object Body { get; } = body;

public override string ToString()
Copy link
Contributor

Choose a reason for hiding this comment

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

Exceptions shouldn't override the ToString method.
To communicate the exception details, use Message and additional properties only.

{
return $"AssemblyAIClientApiException {{ message: {Message}, statusCode: {StatusCode}, body: {Body} }}";
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace AssemblyAI.Core;

public class Environments
public class AssemblyAIClientEnvironment
{
public static string DEFAULT = "https://api.assemblyai.com";
Copy link
Contributor

Choose a reason for hiding this comment

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

DEFAULT should be Default according to .NET naming conventions

}
11 changes: 11 additions & 0 deletions src/AssemblyAI/Core/AssemblyAIClientException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

#nullable enable

namespace AssemblyAI.Core;

/// <summary>
/// Base exception class for all exceptions thrown by the SDK.
/// </summary>
public class AssemblyAIClientException(string message, Exception? innerException = null)
: Exception(message, innerException) { }
3 changes: 2 additions & 1 deletion src/AssemblyAI/Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ namespace AssemblyAI.Core;

internal static class Constants
{
internal const string Version = "0.0.2-alpha";
internal const string Version = "1.0.0-beta";
public const string DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffK";
}
22 changes: 22 additions & 0 deletions src/AssemblyAI/Core/DateTimeSerializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Globalization;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace AssemblyAI.Core;

public class DateTimeSerializer : JsonConverter<DateTime>
{
public override DateTime Read(
ref Utf8JsonReader reader,
System.Type typeToConvert,
JsonSerializerOptions options
)
{
return DateTime.Parse(reader.GetString()!, null, DateTimeStyles.RoundtripKind);
}

public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options)
{
writer.WriteStringValue(value.ToString(Constants.DateTimeFormat));
}
}
Loading
Loading