Skip to content

feat: make provider objects generic#532

Merged
naomi-lgbt merged 7 commits into
mainfrom
feat/generic
Jun 9, 2025
Merged

feat: make provider objects generic#532
naomi-lgbt merged 7 commits into
mainfrom
feat/generic

Conversation

@naomi-lgbt

@naomi-lgbt naomi-lgbt commented May 29, 2025

Copy link
Copy Markdown
Contributor

Proposed changes

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

    • Added a new example script demonstrating the setup and usage of a Deepgram Voice Agent with customizable provider options and event logging.
  • Refactor

    • Consolidated multiple provider types into a single unified provider configuration with attribute-style dictionary access, simplifying customization and extension.
  • Chores

    • Removed specific provider classes and related references, streamlining provider management.
  • Bug Fixes

    • Removed restrictions on keyterm usage in agent listen provider settings, allowing broader model compatibility without validation errors.

@coderabbitai

coderabbitai Bot commented May 29, 2025

Copy link
Copy Markdown
Contributor

"""

Walkthrough

The changes consolidate ListenProvider, SpeakProvider, and ThinkProvider into a single Provider class used throughout the Deepgram agent modules. The provider dataclasses were removed and replaced by a generic dictionary subclass with attribute access. Validation restricting keyterms to "nova-3" models was removed. An example demonstrating agent usage with arbitrary provider keys was added.

Changes

Files/Paths Change Summary
deepgram/init.py, deepgram/client.py, deepgram/clients/init.py,
deepgram/clients/agent/init.py, deepgram/clients/agent/client.py,
deepgram/clients/agent/v1/init.py,
deepgram/clients/agent/v1/websocket/init.py Replaced imports/exports of ListenProvider, SpeakProvider, ThinkProvider with a unified Provider symbol.
deepgram/clients/agent/v1/websocket/options.py Removed ListenProvider, SpeakProvider, ThinkProvider dataclasses; added generic Provider dict subclass; updated Listen, Think, Speak classes to use Provider.
deepgram/clients/agent/v1/websocket/client.py,
deepgram/clients/agent/v1/websocket/async_client.py Removed validation restricting keyterms usage to "nova-3" models in agent listen provider settings.
examples/agent/arbitrary_keys/main.py Added example script demonstrating Deepgram Voice Agent setup with arbitrary keys in provider configuration.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ExampleScript
    participant DeepgramClient
    participant VoiceAgentWS

    User->>ExampleScript: Run main()
    ExampleScript->>DeepgramClient: Initialize with API key
    ExampleScript->>VoiceAgentWS: Configure agent options (audio, providers, etc.)
    ExampleScript->>VoiceAgentWS: Register event handlers
    ExampleScript->>VoiceAgentWS: Start connection with options
    VoiceAgentWS-->>ExampleScript: on_welcome, on_settings, on_error events
    ExampleScript->>VoiceAgentWS: Finish connection
    ExampleScript-->>User: Print and log status
Loading

Suggested reviewers

  • jpvajda
    """

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Pylint (3.3.7)
examples/agent/arbitrary_keys/main.py
deepgram/clients/agent/v1/websocket/options.py
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
examples/agent/arbitrary_keys/main.py (1)

23-100: Well-structured example demonstrating arbitrary provider attributes.

This example effectively demonstrates the new flexible provider configuration with arbitrary keys. The implementation follows good practices with proper error handling, environment variable usage, and resource cleanup.

A few minor suggestions for improvement:

+        # Create chatlog.txt if it doesn't exist and add timestamp
+        timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+        with open("chatlog.txt", 'a') as chatlog:
+            chatlog.write(f"\n=== Session started at {timestamp} ===\n")
+
         def on_welcome(self, welcome, **kwargs):
             print(f"Welcome message received: {welcome}")
             with open("chatlog.txt", 'a') as chatlog:
-                chatlog.write(f"Welcome message: {welcome}\n")
+                chatlog.write(f"[{datetime.now().strftime('%H:%M:%S')}] Welcome: {welcome}\n")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 052aadd and 1973bbc.

📒 Files selected for processing (9)
  • deepgram/__init__.py (0 hunks)
  • deepgram/client.py (0 hunks)
  • deepgram/clients/__init__.py (0 hunks)
  • deepgram/clients/agent/__init__.py (0 hunks)
  • deepgram/clients/agent/client.py (0 hunks)
  • deepgram/clients/agent/v1/__init__.py (0 hunks)
  • deepgram/clients/agent/v1/websocket/__init__.py (0 hunks)
  • deepgram/clients/agent/v1/websocket/options.py (2 hunks)
  • examples/agent/arbitrary_keys/main.py (1 hunks)
💤 Files with no reviewable changes (7)
  • deepgram/client.py
  • deepgram/init.py
  • deepgram/clients/agent/v1/init.py
  • deepgram/clients/agent/client.py
  • deepgram/clients/init.py
  • deepgram/clients/agent/v1/websocket/init.py
  • deepgram/clients/agent/init.py
🧰 Additional context used
🪛 GitHub Actions: Check - lint
deepgram/clients/agent/v1/websocket/options.py

[warning] 228-228: pylint: Missing class docstring (missing-class-docstring)


[warning] 233-233: pylint: Consider explicitly re-raising using 'except KeyError as exc' and 'raise AttributeError(name) from exc' (raise-missing-from)

🔇 Additional comments (3)
examples/agent/arbitrary_keys/main.py (1)

61-61: Excellent demonstration of arbitrary key support.

This line perfectly demonstrates the new capability to add arbitrary attributes to the speak provider, which aligns with the PR objective.

deepgram/clients/agent/v1/websocket/options.py (2)

221-221: Provider type change enables arbitrary attributes.

The change from SpeakProvider to dict successfully enables arbitrary attribute support as demonstrated in the example script.


239-243: Simplified getitem method maintains essential functionality.

The removal of SpeakProvider-specific logic correctly simplifies this method while preserving the Endpoint conversion functionality.

Comment thread deepgram/clients/agent/v1/websocket/options.py Outdated
Comment thread deepgram/clients/agent/v1/websocket/options.py Outdated
@naomi-lgbt naomi-lgbt changed the title feat: support arbitrary attributes for speak provider feat: make provider objects generic Jun 7, 2025
@jpvajda jpvajda mentioned this pull request Jun 9, 2025
4 tasks
Comment thread examples/agent/arbitrary_keys/main.py
Comment thread deepgram/__init__.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (4)
examples/agent/arbitrary_keys/main.py (4)

8-14: Unused imports detected.

Several imported modules (requests, wave, io, time, threading, datetime) are not used in the code and should be removed to improve clarity.

-import requests
-import wave
-import io
-import time
 import os
 import json
-import threading
-from datetime import datetime

31-31: Security concern: API key logging.

Printing "API Key found:" could be misleading and might encourage logging of sensitive information. Consider a more generic success message.

-        print(f"API Key found:")
+        print("API key successfully loaded from environment")

88-88: Remove debug print statement.

The print(options) statement appears to be debug code and should be removed for production-quality examples.

-        print(options)

95-95: Add cleanup for chatlog file.

Consider cleaning up the chatlog.txt file at the end of the example to avoid accumulating test data across runs.

         # Cleanup
         connection.finish()
+        try:
+            os.remove("chatlog.txt")
+        except OSError:
+            pass  # File might not exist or be removable
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4ab6cba and bf825dc.

📒 Files selected for processing (2)
  • deepgram/clients/agent/v1/websocket/options.py (6 hunks)
  • examples/agent/arbitrary_keys/main.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • deepgram/clients/agent/v1/websocket/options.py
🔇 Additional comments (2)
examples/agent/arbitrary_keys/main.py (2)

63-63: Intentional test case correctly implemented.

The arbitrary key addition aligns with the example's purpose of demonstrating error handling for invalid provider configurations. This validates the generic provider functionality.


96-97: Excellent documentation of expected behavior.

The clear explanation of expected failure and instructions for verification make this example very user-friendly and educational.

Comment thread examples/agent/arbitrary_keys/main.py
@naomi-lgbt
naomi-lgbt merged commit 4521048 into main Jun 9, 2025
5 checks passed
@naomi-lgbt
naomi-lgbt deleted the feat/generic branch June 9, 2025 21:39
@coderabbitai coderabbitai Bot mentioned this pull request Jul 1, 2025
8 tasks
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.

3 participants