-
Notifications
You must be signed in to change notification settings - Fork 32
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 TTS and Other REST Refactor #245
Implement TTS and Other REST Refactor #245
Conversation
WalkthroughThis update introduces a significant expansion and refinement to the .NET SDK for Deepgram, focusing on enhancing functionality around speech processing. Key additions include the introduction of a new Changes
Related issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 8
Configuration used: CodeRabbit UI
Files selected for processing (21)
- Deepgram.Dev.sln (2 hunks)
- Deepgram.Tests/Fakes/MockHttpClient.cs (1 hunks)
- Deepgram.Tests/Fakes/MockHttpMessageHandler.cs (2 hunks)
- Deepgram.Tests/UnitTests/ClientTests/SpeakClientTests.cs (1 hunks)
- Deepgram/Abstractions/AbstractRestClient.cs (7 hunks)
- Deepgram/Clients/Analyze/v1/Client.cs (6 hunks)
- Deepgram/Clients/Live/v1/Client.cs (3 hunks)
- Deepgram/Clients/Manage/v1/Client.cs (12 hunks)
- Deepgram/Clients/PreRecorded/v1/Client.cs (6 hunks)
- Deepgram/Clients/Speak/v1/Client.cs (1 hunks)
- Deepgram/Clients/Speak/v1/Constants.cs (1 hunks)
- Deepgram/Clients/Speak/v1/UriSegments.cs (1 hunks)
- Deepgram/Models/Analyze/v1/UrlSource.cs (1 hunks)
- Deepgram/Models/Speak/v1/AsyncResponse.cs (1 hunks)
- Deepgram/Models/Speak/v1/SpeakSchema.cs (1 hunks)
- Deepgram/Models/Speak/v1/SyncResponse.cs (1 hunks)
- Deepgram/Models/Speak/v1/TextSource.cs (1 hunks)
- Deepgram/SpeakClient.cs (1 hunks)
- Deepgram/Utilities/QueryParameterUtil.cs (3 hunks)
- examples/speak/Program.cs (1 hunks)
- examples/speak/Speak.csproj (1 hunks)
Files skipped from review due to trivial changes (5)
- Deepgram.Tests/Fakes/MockHttpClient.cs
- Deepgram/Clients/Speak/v1/Constants.cs
- Deepgram/Clients/Speak/v1/UriSegments.cs
- Deepgram/Models/Analyze/v1/UrlSource.cs
- Deepgram/SpeakClient.cs
Additional comments: 26
examples/speak/Speak.csproj (3)
- 3-7: The project settings for the Speak example are well-configured, adhering to modern .NET best practices by enabling
ImplicitUsings
andNullable
.- 11-11: The inclusion of
Microsoft.Extensions.Http
is appropriate for HTTP operations within the Speak example.- 15-15: The project reference to
Deepgram.csproj
is correctly included, allowing the Speak example to utilize the SDK.Deepgram/Models/Speak/v1/AsyncResponse.cs (1)
- 7-14: The
AsyncResponse
record is well-defined and appropriately uses the record syntax for immutable data modeling. The documentation for theRequestId
property is clear and informative.Deepgram.Tests/Fakes/MockHttpMessageHandler.cs (1)
- 6-6: The introduction of a generic type parameter
T
to theMockHttpMessageHandler
class enhances its flexibility and utility for testing by allowing it to mock responses of any type. This is a valuable improvement for unit testing.Deepgram.Dev.sln (1)
- 14-15: The addition of the "Speak" project to the solution file is correctly implemented, ensuring that the new TTS example is properly included in the solution structure.
Deepgram/Utilities/QueryParameterUtil.cs (1)
- 13-22: The modifications to
GetParameters
to include an optionaladdons
parameter enhance the method's flexibility without introducing any apparent issues. Good use of null checks and URL encoding for security.Deepgram/Clients/Speak/v1/Client.cs (3)
- 27-85: The addition of the
addons
parameter inToStream
enhances the method's flexibility. The secure construction of the query string usingQueryParameterUtil.GetParameters
is commendable. However, consider abstracting the response header parsing into a separate method for improved maintainability and readability.- 88-102: The
ToFile
method correctly utilizes theToStream
method to obtain the TTS response and then saves it to a file usingBinaryWriter
. This approach is efficient and correctly implemented.- 127-152: The callback validation methods
VerifyNoCallBack
andVerifyOneCallBackSet
are correctly implemented, ensuring proper handling of callback URLs. Consider abstracting the repeated validation logic to adhere to the DRY principle, enhancing code maintainability.Deepgram/Clients/Analyze/v1/Client.cs (3)
- 25-29: The addition of the
addons
parameter inAnalyzeUrl
enhances the method's flexibility. The secure construction of the query string usingQueryParameterUtil.GetParameters
is commendable.- 40-43: The refactoring of
AnalyzeFile
to include anaddons
parameter and to call another overload for handling aMemoryStream
is a good practice, promoting code reuse and maintainability.- 90-102: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [72-118]
The callback methods
AnalyzeFileCallBack
andAnalyzeUrlCallBack
are well-implemented, securely handling theaddons
parameter and callback URL. The consistent approach across the SDK enhances maintainability.Deepgram.Tests/UnitTests/ClientTests/SpeakClientTests.cs (1)
- 55-164: The unit tests introduced for the Speak client are comprehensive and correctly verify the behavior of callback URL handling and the
addons
parameter. The use of mocking and assertions is appropriate, ensuring the reliability of the TTS functionalities.Deepgram/Clients/PreRecorded/v1/Client.cs (3)
- 26-30: The addition of the
addons
parameter inTranscribeUrl
enhances the method's flexibility. The secure construction of the query string usingQueryParameterUtil.GetParameters
is commendable.- 41-44: The refactoring of
TranscribeFile
to include anaddons
parameter and to call another overload for handling aMemoryStream
is a good practice, promoting code reuse and maintainability.- 91-103: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [73-120]
The callback methods
TranscribeFileCallBack
andTranscribeUrlCallBack
are well-implemented, securely handling theaddons
parameter and callback URL. The consistent approach across the SDK enhances maintainability.Deepgram/Abstractions/AbstractRestClient.cs (6)
- 42-46: The addition of the
addons
parameter inGetAsync
method enhances the flexibility of API requests by allowing custom query parameters. However, ensure that theQueryParameterUtil.AppendQueryParameters
method properly encodes the parameters to avoid potential security issues like injection attacks.- 132-136: The new
PostAsync
method with theaddons
parameter is a good addition for supporting custom query parameters in POST requests. This aligns with the overall goal of enhancing REST functions in the SDK. Ensure that the content passed to this method is properly validated or sanitized to prevent security vulnerabilities such as injection attacks.- 156-160: The
DeleteAsync
method's modification to include anaddons
parameter is consistent with the enhancements made to other HTTP methods in this class. This consistency in design is beneficial for the SDK's usability. As with other methods, ensure that theaddons
are properly encoded to prevent security issues.- 177-181: The addition of an overload for the
DeleteAsync
method that returns a typeT
is a useful enhancement, providing more flexibility in handling responses from DELETE requests. This change is consistent with the approach taken for other HTTP methods in this class.- 201-210: The
PatchAsync
method's update to include anaddons
parameter is a welcome addition for supporting custom query parameters. The use of conditional compilation to support different HTTP methods based on the target framework is a good practice for ensuring compatibility. Ensure that the content and addons are properly handled to prevent security vulnerabilities.- 232-236: The new
PutAsync
method with theaddons
parameter aligns with the enhancements made to other HTTP methods in this class, providing a consistent and flexible way to include custom query parameters in PUT requests. As always, ensure proper encoding and validation of the parameters to maintain security.Deepgram/Clients/Live/v1/Client.cs (2)
- 63-69: > 📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [66-85]
The addition of the
addons
parameter in theConnect
method is a good enhancement, allowing for more customizable WebSocket connections. Ensure that theaddons
are properly encoded and validated when constructing the URI to prevent potential security issues.
- 289-292: The
GetUri
method now accepts anaddons
parameter, which is used to append custom query parameters to the URI. This change is consistent with the overall goal of enhancing flexibility in the SDK. Ensure that theQueryParameterUtil.GetParameters
method properly encodes the parameters to avoid potential security issues.Deepgram/Clients/Manage/v1/Client.cs (1)
- 23-24: The addition of the
addons
parameter across various methods, starting withGetProjects
, enhances the flexibility and customizability of API requests by allowing custom query parameters. This is a significant improvement in line with the PR objectives. Ensure that theaddons
are properly encoded and validated to prevent security vulnerabilities.
26a5c3f
to
c8c0606
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (21)
- Deepgram.Dev.sln (2 hunks)
- Deepgram.Tests/Fakes/MockHttpClient.cs (1 hunks)
- Deepgram.Tests/Fakes/MockHttpMessageHandler.cs (2 hunks)
- Deepgram.Tests/UnitTests/ClientTests/SpeakClientTests.cs (1 hunks)
- Deepgram/Abstractions/AbstractRestClient.cs (6 hunks)
- Deepgram/Clients/Analyze/v1/Client.cs (6 hunks)
- Deepgram/Clients/Live/v1/Client.cs (3 hunks)
- Deepgram/Clients/Manage/v1/Client.cs (12 hunks)
- Deepgram/Clients/PreRecorded/v1/Client.cs (6 hunks)
- Deepgram/Clients/Speak/v1/Client.cs (1 hunks)
- Deepgram/Clients/Speak/v1/Constants.cs (1 hunks)
- Deepgram/Clients/Speak/v1/UriSegments.cs (1 hunks)
- Deepgram/Models/Analyze/v1/UrlSource.cs (1 hunks)
- Deepgram/Models/Speak/v1/AsyncResponse.cs (1 hunks)
- Deepgram/Models/Speak/v1/SpeakSchema.cs (1 hunks)
- Deepgram/Models/Speak/v1/SyncResponse.cs (1 hunks)
- Deepgram/Models/Speak/v1/TextSource.cs (1 hunks)
- Deepgram/SpeakClient.cs (1 hunks)
- Deepgram/Utilities/QueryParameterUtil.cs (3 hunks)
- examples/speak/Program.cs (1 hunks)
- examples/speak/Speak.csproj (1 hunks)
Files skipped from review as they are similar to previous changes (18)
- Deepgram.Dev.sln
- Deepgram.Tests/Fakes/MockHttpClient.cs
- Deepgram.Tests/Fakes/MockHttpMessageHandler.cs
- Deepgram/Clients/Analyze/v1/Client.cs
- Deepgram/Clients/Live/v1/Client.cs
- Deepgram/Clients/Manage/v1/Client.cs
- Deepgram/Clients/PreRecorded/v1/Client.cs
- Deepgram/Clients/Speak/v1/Client.cs
- Deepgram/Clients/Speak/v1/Constants.cs
- Deepgram/Clients/Speak/v1/UriSegments.cs
- Deepgram/Models/Analyze/v1/UrlSource.cs
- Deepgram/Models/Speak/v1/AsyncResponse.cs
- Deepgram/Models/Speak/v1/SpeakSchema.cs
- Deepgram/Models/Speak/v1/SyncResponse.cs
- Deepgram/Models/Speak/v1/TextSource.cs
- Deepgram/SpeakClient.cs
- examples/speak/Program.cs
- examples/speak/Speak.csproj
Additional comments: 11
Deepgram/Utilities/QueryParameterUtil.cs (2)
- 25-44: The implementation of
AppendQueryParameters
method looks good. It correctly handles null checks and efficiently appends query parameters to the URI.- 13-22: The modification to include an optional
addons
parameter in theGetParameters
method enhances its flexibility and aligns with the PR's objectives.Deepgram.Tests/UnitTests/ClientTests/SpeakClientTests.cs (4)
- 55-81: The test
StreamCallBack_With_CallBack_Property_Should_Call_PostAsync_Returning_SyncResponse
is well-structured and correctly verifies the functionality.- 83-114: The test
StreamCallBack_With_CallBack_Parameter_Should_Call_PostAsync_Returning_SyncResponse
effectively verifies the functionality with theCallBack
parameter set.- 118-140: The test
StreamCallBack_Throw_ArgumentException_With_CallBack_Property_And_CallBack_Parameter_Set
correctly verifies that anArgumentException
is thrown when both the property and parameter are set.- 142-164: The test
StreamCallBack_Should_Throw_ArgumentException_With_No_CallBack_Set
effectively ensures that anArgumentException
is thrown when noCallBack
is provided, which is crucial for the method's correctness.Deepgram/Abstractions/AbstractRestClient.cs (5)
- 39-43: The modification to include an optional
addons
parameter in theGetAsync
method aligns with the PR's objectives and is correctly implemented.- 129-133: The addition of the new
PostAsync
method with anaddons
parameter is a valuable enhancement, providing flexibility for making POST requests with custom query parameters.- 153-157: The modifications to include an
addons
parameter in theDeleteAsync
method and the addition of a newDeleteAsync
method returning a typeT
enhance flexibility and align with the PR's objectives.- 198-203: The modification to include an
addons
parameter in thePatchAsync
method enhances its flexibility for PATCH requests and is correctly implemented.- 229-233: The addition of the new
PutAsync
method with anaddons
parameter is a valuable enhancement, providing flexibility for making PUT requests with custom query parameters.
Addresses issue: #244
Partially addresses: #234
Major changes include:
There are
TODO
s for logging (and comments) which I will get back to when I have a logging mechanism with verbosity levels worked. Existing issues for Comments #210 and Logging #219 already exist as a reminder.Summary by CodeRabbit
New Features
addons
parameters across various client methods, enabling extended functionality in speech processing tasks.Bug Fixes
Refactor
Documentation