deepgram / deepgram-go-sdk

Go SDK for Deepgram's automated speech recognition APIs.
https://developers.deepgram.com
MIT License
31 stars 27 forks source link

Address Common vs REST Defaults for Clients #254

Closed dvonthenen closed 2 months ago

dvonthenen commented 2 months ago

Proposed changes

This addresses which internal client to use in which situation. It turned out that the Common Client was being used in just about every situation and that the REST client, which is a lower-level client (although not being used), had a more restricted options set.

This clears up the confusion in the SDK and also makes the various level of client (API specific [most specific] - common - rest - HTTP [most general]). These are all internal changes not exposed to the user.

Tested all examples and they seem to work just fine.

Types of changes

What types of changes does your code introduce to the community Go SDK? Put an x in the boxes that apply

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

Further comments

NA

Summary by CodeRabbit

coderabbitai[bot] commented 2 months ago

[!WARNING]

Rate limit exceeded

@dvonthenen has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 21 minutes and 37 seconds before requesting another review.

How to resolve this issue? After the wait time has elapsed, a review can be triggered using the `@coderabbitai review` command as a PR comment. Alternatively, push new commits to this PR. We recommend that you space out your commits to avoid hitting the rate limit.
How do rate limits work? CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our [FAQ](https://coderabbit.ai/docs/faq) for further information.
Commits Files that changed from the base of the PR and between 94d34754fe33e28845f0666f45e7b4f27d910c2a and f038bf5e70e22979d5c54d4036a9799bab602196.

Walkthrough

The changes streamline and update the functionality across several packages in the codebase. Key modifications include simplifying WebSocket initialization, updating request handling methods, embedding RESTClient types for more consistent API usage, and marking fields as deprecated. These transformations bring more uniformity, improve error handling, and prepare the code for future updates.

Changes

File Path Change Summary
examples/text-to-speech/.../main.go Replaced speak.NewWebSocket call with speak.NewWebSocketWithDefaults for simplified parameters.
pkg/api/manage/v1/manage.go Changed Client.Client field to Client.RESTClient during initialization.
pkg/api/speak/v1/rest/speak.go Removed logging statement fmt.Printf("retVal: %v\n", retVal) from performAction function.
pkg/client/analyze/v1/client.go Updated DoText and DoURL methods to use c.Do instead of custom c.HTTPClient.Do execution blocks.
pkg/client/common/v1/common.go SetupRequest method now sets the "Content-Type" header to "application/json"; ProcessRequest method removed; HandleResponse method now logs HTTP response handling.
pkg/client/common/v1/types.go Changed Client struct to embed RESTClient using an alias instead of rest.Client; added type RESTClient = rest.Client.
pkg/client/interfaces/v1/types-stream.go Deprecated Tier field in LiveTranscriptionOptions struct, indicating future removal.
pkg/client/listen/v1/rest/client.go Updated DoStream method to use RESTClient methods for request setup and execution.
pkg/client/manage/v1/client.go Updated APIRequest method to use c.Do for executing HTTP requests, affecting header setting and response processing.
pkg/client/rest/v1/rest.go Added SetupRequest function to prepare REST requests; updated Do function to handle HTTP and Deepgram-specific errors.
pkg/client/speak/v1/rest/client.go Modified DoText method to use JSON encoding for text, adjusted request setup to use JSON text, updated comments and logging, and added handling of response headers using HTTPClient and HandleResponse.

Sequence Diagrams

WebSocket Initialization

sequenceDiagram
    participant Main
    participant Speak
    Note right of Main: Old Flow
    Main->>Speak: speak.NewWebSocket(ctx, "", cOptions, ttsOptions, callback)
    Note right of Main: New Flow
    Main->>Speak: speak.NewWebSocketWithDefaults(ctx, ttsOptions, callback)

Client Setup and Request Handling

sequenceDiagram
    participant Client
    participant Common
    Note right of Client: Old Flow
    Client->>Common: c.HTTPClient.Do(ctx, req, func(res *http.Response) error { ... })
    Note right of Client: New Flow
    Client->>Common: c.Do(ctx, req, resBody)

Deprecated Field

sequenceDiagram
    participant Client
    Note right of Client: New Flow
    Client->>Note: Tier in LiveTranscriptionOptions <br>Deprecated: This field will be <br>removed in a future release.

These diagrams provide a visual guide to key changes in control flow and functional updates in the codebase. They illustrate both old and new implementation flows to highlight differences.


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?

Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` 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) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.