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

Fix for Deepgram async websocket #486

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

xzys
Copy link

@xzys xzys commented Nov 20, 2024

Proposed changes

The Python websockets library seems to accept additional_headers not extra_headers:
https://github.com/python-websockets/websockets/blob/main/src/websockets/asyncio/client.py#L79

Fixes #483

Types of changes

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

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update or tests (if none of the other choices 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.

  • I have read the CONTRIBUTING doc
  • I have lint'ed all of my code using repo standards
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

Summary by CodeRabbit

  • New Features

    • Transitioned the project configuration from Poetry to Setuptools for improved dependency management.
  • Bug Fixes

    • Updated the websockets library version to ensure compatibility and access to new features.
  • Chores

    • Made structural updates to the configuration files (pyproject.toml, requirements.txt, setup.py) to reflect the new dependency management approach.

Copy link
Contributor

coderabbitai bot commented Nov 20, 2024

Walkthrough

The changes in this pull request involve modifications to the WebSocket handling in the AbstractAsyncWebSocketClient class and a transition from a Poetry-based to a Setuptools-based configuration in the pyproject.toml file. Specifically, the extra_headers parameter in the WebSocket connection method has been renamed to additional_headers to accommodate updates in the websockets library. Additionally, the version requirements for the websockets library have been updated across multiple configuration files, allowing compatibility with version 14.0.

Changes

File Change Summary
deepgram/clients/common/v1/abstract_async_websocket.py Renamed extra_headers to additional_headers in the start method of AbstractAsyncWebSocketClient.
pyproject.toml Transitioned from Poetry to Setuptools; updated websockets dependency version from ^12.0 to ^14.1.
requirements.txt Updated websockets version from 12.* to 14.*.
setup.py Changed websockets requirement from >=12.0,<14.0 to >=14.0, removing the upper version limit.

Assessment against linked issues

Objective Addressed Explanation
Ensure compatibility with WebSocket version 14.0 by renaming extra_headers to additional_headers (#483)
Maintain existing functionality while accommodating the new WebSocket version (#483)

Possibly related PRs


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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@jjmaldonis
Copy link
Contributor

Hi @xzys thanks for the PR!

We'll need to update the version of the websocket dependency in the relevant files (requirements.txt, setup.py, and pyproject.toml) in addition to making the change you've already made.

If you want to make that change, the rest of our team will review this. Otherwise we'll work off your changes.

@xzys xzys force-pushed the fix-async-websocket-headers branch from b376970 to 6921dd2 Compare November 26, 2024 15:33
@xzys xzys marked this pull request as ready for review November 26, 2024 15:35
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (3)
setup.py (1)

31-31: Consider adding an upper bound version constraint.

While the current change fixes the immediate issue, having no upper bound on the websockets version could lead to compatibility issues if future versions introduce breaking changes.

Consider using a more specific version range:

-        "websockets>=14.0",
+        "websockets>=14.0,<15.0",
pyproject.toml (1)

Remove Poetry configuration and maintain Setuptools as the sole build system

The codebase is actively using Setuptools as its build system, evidenced by:

  • An actively maintained setup.py with complete package configuration
  • README.md documentation using pip-based installation instructions
  • requirements.txt following pip/setuptools conventions
  • No active usage of Poetry in the codebase

The commented-out Poetry configuration in pyproject.toml is obsolete and should be removed to prevent confusion. The active Setuptools configuration in pyproject.toml aligns with the rest of the build infrastructure.

🔗 Analysis chain

Line range hint 1-54: Clarify build system configuration strategy

The file contains both Setuptools and Poetry configurations, with Poetry sections partially commented out. This dual configuration could lead to confusion about which build system should be used.

Let's check if this is part of a broader migration:

Consider:

  1. If migrating to Setuptools, remove commented Poetry configuration
  2. If keeping Poetry, restore its configuration and remove Setuptools
  3. Document the intended build system in README.md

Let me gather more information about the build system configuration by checking the content of setup.py and requirements.txt, and also look for any migration-related information in README.md.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for other build configuration files
echo "Checking for related build files..."
fd -t f "setup\.py|poetry\.lock|requirements\.txt"

# Check if other files reference poetry
echo -e "\nChecking for poetry references..."
rg -i "poetry" --type yaml --type toml

Length of output: 585


Script:

#!/bin/bash
# Check setup.py content
echo "=== setup.py content ==="
cat setup.py

echo -e "\n=== requirements.txt content ==="
cat requirements.txt

echo -e "\n=== Checking README.md for build system info ==="
rg -i "(\bpoetry\b|\bsetuptools\b|\bbuild\b|\binstall\b)" README.md

Length of output: 2810

deepgram/clients/common/v1/abstract_async_websocket.py (1)

138-141: Consider adding a version compatibility note in docstring

Since this change introduces a dependency on websockets ≥14.0, it would be helpful to document this requirement in the class or method docstring.

Add a note like:

    """
    Starts the WebSocket connection for live transcription.
+   
+   Note: Requires websockets library version 14.0 or higher.
    """
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 7df7b27 and 855685c.

📒 Files selected for processing (4)
  • deepgram/clients/common/v1/abstract_async_websocket.py (1 hunks)
  • pyproject.toml (1 hunks)
  • requirements.txt (1 hunks)
  • setup.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • requirements.txt
🔇 Additional comments (4)
setup.py (1)

31-31: LGTM! Version update addresses the websockets compatibility issue.

The update to websockets>=14.0 correctly addresses issue #483 by allowing the use of the additional_headers parameter instead of the deprecated extra_headers.

Let's verify the dependency consistency and check for security advisories:

✅ Verification successful

The previous search didn't find the files, so let's try with fd. We need to verify the dependency consistency across all requirement files before making a final decision. The security check showed no critical/high vulnerabilities affecting version 14.0 or later, which is good, but we still need to confirm the dependency specifications are consistent across the project.


LGTM on the websockets upgrade, with consistent dependency specifications

The dependency update to websockets>=14.0 is safe and properly synchronized across the project:

  • requirements.txt specifies websockets==14.*
  • pyproject.toml (poetry) specifies websockets = "^14.1"
  • No critical/high security vulnerabilities affect version 14.0 or later
  • The version constraints are consistent and maintain compatibility
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify dependency consistency across files and check for security advisories

# Check dependency specifications in other files
echo "Checking dependency files for consistency..."
rg -g "requirements*.txt|pyproject.toml" "websockets"

# Check for security advisories
echo "Checking for security advisories..."
gh api graphql -f query='
{
  securityVulnerabilities(first: 5, ecosystem: PIP, package: "websockets", severities: [CRITICAL, HIGH]) {
    nodes {
      advisory {
        summary
        severity
        publishedAt
      }
      vulnerableVersionRange
      firstPatchedVersion {
        identifier
      }
    }
  }
}'

Length of output: 1208


Script:

#!/bin/bash
# Let's check for dependency files in a different way and also look for any test requirements
fd -e txt -e toml "requirements|pyproject" --exec cat {} \; 2>/dev/null

Length of output: 2243

pyproject.toml (2)

34-34: LGTM: Websockets version update aligns with PR objectives

The update to websockets = "^14.1" correctly addresses issue #483 by supporting version 14.0+ where the additional_headers parameter is required.


Line range hint 18-18: Update version placeholder in Poetry configuration

The version is currently set to a placeholder 3.X.Y with a comment requesting update. This should be replaced with the actual version number.

Let's check the current version:

✅ Verification successful

Version placeholder should be updated to 0.0.0

The version in pyproject.toml is currently set to a placeholder 3.X.Y, but based on the codebase analysis, it should be updated to 0.0.0 to match the version defined in deepgram/__init__.py. This ensures consistency across the package.

  • Update the version in pyproject.toml from version = "3.X.Y" to version = "0.0.0"
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for version references
echo "Checking version in deepgram module..."
rg -A 1 "__version__" 

echo -e "\nChecking version in other config files..."
rg -A 1 "version\s*=" --type=toml --type=python

Length of output: 3455


Script:

#!/bin/bash
# Check pyproject.toml content
echo "Checking pyproject.toml content..."
cat pyproject.toml

Length of output: 1590

deepgram/clients/common/v1/abstract_async_websocket.py (1)

139-139: LGTM! Parameter name updated correctly for websockets v14.0

The change from extra_headers to additional_headers aligns with the websockets library v14.0 API. This fixes the TypeError mentioned in issue #483.

Let's verify the websockets version constraints in the project configuration:

✅ Verification successful

Version constraints are properly updated for websockets v14.0

The version constraints are correctly specified across all configuration files:

  • pyproject.toml: websockets = "^14.1"
  • requirements.txt: websockets==14.*
  • setup.py: websockets>=14.0

These constraints ensure compatibility with the new additional_headers parameter, making the code change safe and complete.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check websockets version constraints across project files

echo "Checking pyproject.toml..."
cat pyproject.toml 2>/dev/null | grep -A 5 "websockets"

echo -e "\nChecking requirements.txt..."
cat requirements.txt 2>/dev/null | grep "websockets"

echo -e "\nChecking setup.py..."
cat setup.py 2>/dev/null | grep -A 5 "websockets"

Length of output: 644

@xzys
Copy link
Author

xzys commented Nov 26, 2024

@jjmaldonis Added the changes to upgrade websockets to 14.1. Didn't add any additional tests, but existing tests are passing (except for some minor transcription errors, aka not picking up commas)

@jpvajda
Copy link
Contributor

jpvajda commented Dec 2, 2024

@xzys We have a concern that this change will be breaking and we'll need to consider how to offer backwards compatibility for users still using older versions of the the Python websockets library.

Ideally both additional_headers and extra_headers would work depending on what version the user is using. Is that something you'd be able to help with on this PR?

cc @jjmaldonis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deepgram SDK Fails with WebSocket Version 14.0 - Unexpected Keyword Argument extra_headers
3 participants