-
Notifications
You must be signed in to change notification settings - Fork 94
fix: correct the structures for custom speak endpoints #527
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
Conversation
WalkthroughThe changes remove the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ExampleScript as main.py
participant DeepgramClient
participant AgentWebSocket
User->>ExampleScript: Run script
ExampleScript->>DeepgramClient: Initialize with options
DeepgramClient->>AgentWebSocket: Connect (version="1")
AgentWebSocket-->>ExampleScript: on_open event
loop Event Handling
AgentWebSocket-->>ExampleScript: Various events (audio, welcome, settings, etc.)
ExampleScript->>AgentWebSocket: Respond to function_call_request (if any)
end
User->>ExampleScript: Input to stop
ExampleScript->>AgentWebSocket: Close connection
Assessment against linked issues
Suggested reviewers
Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. ✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration 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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
examples/agent/11_labs/main.py (1)
147-147
: Potential security concern: API key placeholder should use a clearer template.While this is an example, it's best to use a clearly templated value for API keys to avoid confusion.
-options.agent.speak.endpoint.headers = { "xi-api-key": "PUT A KEY HERE"} +options.agent.speak.endpoint.headers = { "xi-api-key": "YOUR_ELEVEN_LABS_API_KEY"}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 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
(5 hunks)examples/agent/11_labs/main.py
(1 hunks)
💤 Files with no reviewable changes (7)
- deepgram/init.py
- deepgram/client.py
- deepgram/clients/agent/init.py
- deepgram/clients/agent/v1/websocket/init.py
- deepgram/clients/agent/client.py
- deepgram/clients/init.py
- deepgram/clients/agent/v1/init.py
🔇 Additional comments (15)
deepgram/clients/agent/v1/websocket/options.py (7)
5-5
: API enhancement: Type import updated to support simplified header handling.The import statement now includes the
Dict
type, which is required for the new dictionary-based header handling approach.
68-68
: Improved flexibility: Method field now properly handles None values.The
method
field in theEndpoint
class now defaults toNone
with appropriate metadata configuration to exclude it when serializing if it has no value, allowing for more flexible API usage.
70-72
: Simplified header handling: Replaced custom Header class with standard Dict.This change replaces a custom
Header
dataclass with a standard Python dictionary, which simplifies the API and makes it more intuitive to use.
76-77
: Robust type handling: Ensures header keys and values are strings.The
__getitem__
method now ensures that all header keys and values are properly converted to strings, which is important for HTTP header consistency.
91-93
: Consistent header handling: Function class updated to use Dict.The
Function
class now also usesDict[str, str]
for headers, maintaining consistency with theEndpoint
class and simplifying the overall API.
105-106
: Consistent string conversion: Function headers converted to strings.Similar to the
Endpoint
class, theFunction
class's__getitem__
method now ensures header keys and values are strings, maintaining consistency across the API.
237-237
: Improved docstring clarity.The docstring has been simplified for better readability while maintaining its descriptive purpose.
examples/agent/11_labs/main.py (8)
1-32
: Well-structured imports and validation for a comprehensive example.This new example file properly imports all necessary components from the Deepgram SDK and includes helpful debug prints to validate import success, which is excellent for diagnostic purposes.
37-69
: Well-structured client setup with comprehensive event handling.The main function properly initializes the DeepgramClient with appropriate options and establishes event handlers for binary data. The global warning flag prevents repeated notifications about binary data.
70-112
: Comprehensive event handlers for all agent interactions.The example includes handlers for all relevant agent events (welcome, settings, conversation, speaking, thinking, etc.), providing a complete reference for implementing a fully functional agent interaction.
85-97
: Robust function call request handling with proper error management.This handler properly processes function call requests and demonstrates how to send responses back to the agent, with appropriate exception handling to catch and report any errors.
113-132
: Complete event registration for all WebSocket events.The code registers handlers for all available agent WebSocket events, providing a comprehensive example of how to interact with the Deepgram agent API.
133-149
: Demonstrates the new simplified header handling approach.This section shows how to configure the agent with different providers, including the use of the new dictionary-based header approach on line 147. The example demonstrates integration with an external Eleven Labs TTS service.
options.agent.speak.endpoint.headers = {"xi-api-key": "PUT A KEY HERE"}
162-169
: Excellent error handling with detailed diagnostics.The error handling section provides comprehensive details about potential import errors, which is very helpful for diagnosing issues when using the example.
172-174
: Standard Python entry point.The file includes a proper
if __name__ == "__main__"
guard to ensure the main function is only called when the script is run directly.
@naomi-lgbt just confirming, I think we can close this now? |
Closes #525
Summary by CodeRabbit
New Features
Refactor
Header
dataclass with standard Python dictionaries for headers.Chores