Conversation
WalkthroughThis update refactors the handling of function call requests and responses in the Deepgram SDK to align with the latest API specification. It introduces a new Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant SDK
participant DeepgramAPI
Client->>SDK: Create FunctionCallRequest (with functions list)
SDK->>DeepgramAPI: Send FunctionCallRequest (serialized)
DeepgramAPI-->>SDK: Return FunctionCallResponse (with id, name, content)
SDK-->>Client: Deserialize and provide FunctionCallResponse
Suggested reviewers
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)deepgram/__init__.pydeepgram/client.pydeepgram/clients/__init__.py
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (10)
🧰 Additional context used🧠 Learnings (11)📓 Common learningsdeepgram/clients/agent/v1/__init__.py (10)deepgram/client.py (10)deepgram/clients/agent/__init__.py (10)deepgram/clients/agent/client.py (10)deepgram/clients/agent/v1/websocket/__init__.py (10)deepgram/__init__.py (10)deepgram/clients/agent/v1/websocket/options.py (10)deepgram/clients/__init__.py (10)deepgram/clients/agent/v1/websocket/response.py (6)tests/unit_test/test_unit_function_call.py (2)🧬 Code Graph Analysis (8)deepgram/clients/agent/v1/__init__.py (1)
deepgram/client.py (1)
deepgram/clients/agent/__init__.py (1)
deepgram/clients/agent/client.py (1)
deepgram/clients/agent/v1/websocket/__init__.py (1)
deepgram/__init__.py (1)
deepgram/clients/__init__.py (1)
deepgram/clients/agent/v1/websocket/response.py (1)
🔇 Additional comments (15)
✨ Finishing Touches
🧪 Generate unit tests
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 (
|
|
Please merge this when you can <3 or the python SDK is unusable for function calling |
Fixes #528
TL;DR
This PR updates the Deepgram Python SDK's function call implementation to match the official API specification.
Before: Used flat structure with
function_name,function_call_id,input/output.After: Uses proper object structure with
functionsarray containing objects withid,name,arguments,client_sidefields for requests andid,name,contentfor responses. Includes comprehensive unit tests and maintains backward compatibility by removing deprecated fields.Changes Made
1. Updated Data Structures
FunctionCallRequest (NEW):
functions: List[FunctionCall]__post_init__method to convert dict functions toFunctionCallobjectsFunctionCall (NEW):
id,name,arguments,client_sideFunctionCallResponse (UPDATED):
function_call_id,outputtoid,name,content2. Updated Import Hierarchy
Added cascading imports across all
__init__.pyfiles to support clean imports:from deepgram import FunctionCall, FunctionCallRequest, FunctionCallResponsedeepgram/__init__.py,deepgram/client.py,deepgram/clients/__init__.pydeepgram/clients/agent/__init__.py,deepgram/clients/agent/v1/__init__.pydeepgram/clients/agent/v1/websocket/__init__.py3. Comprehensive Unit Tests
Created
tests/unit_test/test_unit_function_call.pywith 21 tests covering:4. Specification Compliance
Official Deepgram Function Call Request:
{ "type": "FunctionCallRequest", "functions": [ { "id": "unique_id_123", "name": "get_weather", "arguments": "{\"location\": \"NYC\"}", "client_side": true } ] }Official Deepgram Function Call Response:
{ "type": "FunctionCallResponse", "id": "unique_id_123", "name": "get_weather", "content": "Sunny, 75°F" }5. Backward Compatibility
function_name,function_call_id,input,outputTesting
Files Modified
deepgram/clients/agent/v1/websocket/response.py- AddedFunctionCall, updatedFunctionCallRequestdeepgram/clients/agent/v1/websocket/options.py- UpdatedFunctionCallResponsedeepgram/__init__.py- Added function call importsdeepgram/client.py- Added function call importsdeepgram/clients/__init__.py- Added function call importsdeepgram/clients/agent/__init__.py- Added function call importsdeepgram/clients/agent/v1/__init__.py- Added function call importsdeepgram/clients/agent/v1/websocket/__init__.py- Added function call importstests/unit_test/test_unit_function_call.py- NEW comprehensive unit testsAPI Impact
url/methodfieldsMigration Guide
Before (Deprecated):
After (Current):
Types of changes
What types of changes does your code introduce to the community Python SDK?
Put an
xin the boxes that applyChecklist
Put an
xin 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.Summary by CodeRabbit
New Features
FunctionCallentity for handling function call data within requests and responses.FunctionCallRequestto support multiple function calls and improved data access patterns.FunctionCallResponsewith new fields for better clarity and structure.Tests
FunctionCall,FunctionCallRequest, andFunctionCallResponseto ensure correct behavior and compatibility.