Skip to content

Commit 144588b

Browse files
committed
fix: function calls
1 parent eca4b1e commit 144588b

File tree

10 files changed

+552
-5
lines changed

10 files changed

+552
-5
lines changed

deepgram/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@
324324
ConversationTextResponse,
325325
UserStartedSpeakingResponse,
326326
AgentThinkingResponse,
327+
FunctionCall,
327328
FunctionCallRequest,
328329
AgentStartedSpeakingResponse,
329330
AgentAudioDoneResponse,

deepgram/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@
338338
ConversationTextResponse,
339339
UserStartedSpeakingResponse,
340340
AgentThinkingResponse,
341+
FunctionCall,
341342
FunctionCallRequest,
342343
AgentStartedSpeakingResponse,
343344
AgentAudioDoneResponse,

deepgram/clients/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@
347347
ConversationTextResponse,
348348
UserStartedSpeakingResponse,
349349
AgentThinkingResponse,
350+
FunctionCall,
350351
FunctionCallRequest,
351352
AgentStartedSpeakingResponse,
352353
AgentAudioDoneResponse,

deepgram/clients/agent/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
ConversationTextResponse,
2323
UserStartedSpeakingResponse,
2424
AgentThinkingResponse,
25+
FunctionCall,
2526
FunctionCallRequest,
2627
AgentStartedSpeakingResponse,
2728
AgentAudioDoneResponse,

deepgram/clients/agent/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
ConversationTextResponse as LatestConversationTextResponse,
2222
UserStartedSpeakingResponse as LatestUserStartedSpeakingResponse,
2323
AgentThinkingResponse as LatestAgentThinkingResponse,
24+
FunctionCall as LatestFunctionCall,
2425
FunctionCallRequest as LatestFunctionCallRequest,
2526
AgentStartedSpeakingResponse as LatestAgentStartedSpeakingResponse,
2627
AgentAudioDoneResponse as LatestAgentAudioDoneResponse,
@@ -70,6 +71,7 @@
7071
ConversationTextResponse = LatestConversationTextResponse
7172
UserStartedSpeakingResponse = LatestUserStartedSpeakingResponse
7273
AgentThinkingResponse = LatestAgentThinkingResponse
74+
FunctionCall = LatestFunctionCall
7375
FunctionCallRequest = LatestFunctionCallRequest
7476
AgentStartedSpeakingResponse = LatestAgentStartedSpeakingResponse
7577
AgentAudioDoneResponse = LatestAgentAudioDoneResponse

deepgram/clients/agent/v1/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
ConversationTextResponse,
2727
UserStartedSpeakingResponse,
2828
AgentThinkingResponse,
29+
FunctionCall,
2930
FunctionCallRequest,
3031
AgentStartedSpeakingResponse,
3132
AgentAudioDoneResponse,

deepgram/clients/agent/v1/websocket/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
ConversationTextResponse,
1919
UserStartedSpeakingResponse,
2020
AgentThinkingResponse,
21+
FunctionCall,
2122
FunctionCallRequest,
2223
AgentStartedSpeakingResponse,
2324
AgentAudioDoneResponse,

deepgram/clients/agent/v1/websocket/options.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,9 @@ class FunctionCallResponse(BaseResponse):
448448
"""
449449

450450
type: str = "FunctionCallResponse"
451-
function_call_id: str = field(default="")
452-
output: str = field(default="")
451+
id: str = field(default="")
452+
name: str = field(default="")
453+
content: str = field(default="")
453454

454455

455456
# Agent Keep Alive

deepgram/clients/agent/v1/websocket/response.py

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,43 @@ class AgentThinkingResponse(BaseResponse):
6868
content: str
6969

7070

71+
@dataclass
72+
class FunctionCall(BaseResponse):
73+
"""
74+
Individual function call within a FunctionCallRequest.
75+
"""
76+
77+
id: str
78+
name: str
79+
arguments: str
80+
client_side: bool
81+
82+
7183
@dataclass
7284
class FunctionCallRequest(BaseResponse):
7385
"""
7486
The FunctionCallRequest message is used to call a function from the server to the client.
7587
"""
7688

7789
type: str
78-
function_name: str
79-
function_call_id: str
80-
input: str
90+
functions: List[FunctionCall]
91+
92+
def __post_init__(self):
93+
"""Convert dict functions to FunctionCall objects if needed."""
94+
if self.functions:
95+
self.functions = [
96+
FunctionCall.from_dict(func) if isinstance(func, dict) else func
97+
for func in self.functions
98+
]
99+
100+
def __getitem__(self, key):
101+
_dict = self.to_dict()
102+
if "functions" in _dict and isinstance(_dict["functions"], list):
103+
_dict["functions"] = [
104+
FunctionCall.from_dict(func) if isinstance(func, dict) else func
105+
for func in _dict["functions"]
106+
]
107+
return _dict[key]
81108

82109

83110
@dataclass

0 commit comments

Comments
 (0)