Skip to content

Commit 37c9e23

Browse files
committed
SDK regeneration
1 parent 816ca6c commit 37c9e23

10 files changed

Lines changed: 84 additions & 96 deletions

.fern/metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
"skip_validation": true
1717
}
1818
},
19-
"originGitCommit": "aa8e0677bcaea82c02a5934c61d195b35921b33d",
19+
"originGitCommit": "14bcc648246f9ac9fb131ba74e7bdaf0cc515238",
2020
"sdkVersion": "6.1.2"
2121
}

poetry.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/deepgram/agent/v1/socket_client.py

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import json
44
import logging
55
import typing
6+
from json.decoder import JSONDecodeError
67

8+
import websockets
79
import websockets.sync.connection as websockets_sync_connection
810
from ...core.events import EventEmitterMixin, EventType
911
from ...core.unchecked_base_model import construct_type
@@ -37,26 +39,6 @@
3739
from websockets import WebSocketClientProtocol # type: ignore
3840

3941
_logger = logging.getLogger(__name__)
40-
41-
42-
def _sanitize_numeric_types(obj: typing.Any) -> typing.Any:
43-
"""
44-
Recursively convert float values that are whole numbers to int.
45-
46-
Workaround for Fern-generated models that type integer API fields
47-
(like sample_rate) as float, causing JSON serialization to produce
48-
values like 44100.0 instead of 44100. The Deepgram API rejects
49-
float representations of integer fields.
50-
51-
See: https://github.com/deepgram/internal-api-specs/issues/205
52-
"""
53-
if isinstance(obj, dict):
54-
return {k: _sanitize_numeric_types(v) for k, v in obj.items()}
55-
elif isinstance(obj, list):
56-
return [_sanitize_numeric_types(item) for item in obj]
57-
elif isinstance(obj, float) and obj.is_integer():
58-
return int(obj)
59-
return obj
6042
V1SocketClientResponse = typing.Union[
6143
AgentV1ReceiveFunctionCallResponse,
6244
AgentV1PromptUpdated,
@@ -88,7 +70,7 @@ async def __aiter__(self):
8870
yield message
8971
else:
9072
try:
91-
yield construct_type(type_=V1SocketClientResponse, object_=json.loads(message)) # type: ignore
73+
yield construct_type(V1SocketClientResponse, json.loads(message)) # type: ignore
9274
except Exception:
9375
_logger.warning(
9476
"Skipping unknown WebSocket message; update your SDK version to support new message types."
@@ -113,14 +95,14 @@ async def start_listening(self):
11395
else:
11496
json_data = json.loads(raw_message)
11597
try:
116-
parsed = construct_type(type_=V1SocketClientResponse, object_=json_data) # type: ignore
98+
parsed = construct_type(V1SocketClientResponse, json_data) # type: ignore
11799
except Exception:
118100
_logger.warning(
119101
"Skipping unknown WebSocket message; update your SDK version to support new message types."
120102
)
121103
continue
122104
await self._emit_async(EventType.MESSAGE, parsed)
123-
except Exception as exc:
105+
except (websockets.WebSocketException, JSONDecodeError) as exc:
124106
await self._emit_async(EventType.ERROR, exc)
125107
finally:
126108
await self._emit_async(EventType.CLOSE, None)
@@ -160,12 +142,12 @@ async def send_function_call_response(self, message: AgentV1SendFunctionCallResp
160142
"""
161143
await self._send_model(message)
162144

163-
async def send_keep_alive(self, message: typing.Optional[AgentV1KeepAlive] = None) -> None:
145+
async def send_keep_alive(self, message: AgentV1KeepAlive) -> None:
164146
"""
165147
Send a message to the websocket connection.
166148
The message will be sent as a AgentV1KeepAlive.
167149
"""
168-
await self._send_model(message or AgentV1KeepAlive(type="KeepAlive"))
150+
await self._send_model(message)
169151

170152
async def send_update_prompt(self, message: AgentV1UpdatePrompt) -> None:
171153
"""
@@ -197,7 +179,7 @@ async def recv(self) -> V1SocketClientResponse:
197179
return data # type: ignore
198180
json_data = json.loads(data)
199181
try:
200-
return construct_type(type_=V1SocketClientResponse, object_=json_data) # type: ignore
182+
return construct_type(V1SocketClientResponse, json_data) # type: ignore
201183
except Exception:
202184
_logger.warning("Skipping unknown WebSocket message; update your SDK version to support new message types.")
203185
return json_data # type: ignore
@@ -214,7 +196,7 @@ async def _send_model(self, data: typing.Any) -> None:
214196
"""
215197
Send a Pydantic model to the websocket connection.
216198
"""
217-
await self._send(_sanitize_numeric_types(data.dict()))
199+
await self._send(data.dict())
218200

219201

220202
class V1SocketClient(EventEmitterMixin):
@@ -228,7 +210,7 @@ def __iter__(self):
228210
yield message
229211
else:
230212
try:
231-
yield construct_type(type_=V1SocketClientResponse, object_=json.loads(message)) # type: ignore
213+
yield construct_type(V1SocketClientResponse, json.loads(message)) # type: ignore
232214
except Exception:
233215
_logger.warning(
234216
"Skipping unknown WebSocket message; update your SDK version to support new message types."
@@ -253,14 +235,14 @@ def start_listening(self):
253235
else:
254236
json_data = json.loads(raw_message)
255237
try:
256-
parsed = construct_type(type_=V1SocketClientResponse, object_=json_data) # type: ignore
238+
parsed = construct_type(V1SocketClientResponse, json_data) # type: ignore
257239
except Exception:
258240
_logger.warning(
259241
"Skipping unknown WebSocket message; update your SDK version to support new message types."
260242
)
261243
continue
262244
self._emit(EventType.MESSAGE, parsed)
263-
except Exception as exc:
245+
except (websockets.WebSocketException, JSONDecodeError) as exc:
264246
self._emit(EventType.ERROR, exc)
265247
finally:
266248
self._emit(EventType.CLOSE, None)
@@ -300,12 +282,12 @@ def send_function_call_response(self, message: AgentV1SendFunctionCallResponse)
300282
"""
301283
self._send_model(message)
302284

303-
def send_keep_alive(self, message: typing.Optional[AgentV1KeepAlive] = None) -> None:
285+
def send_keep_alive(self, message: AgentV1KeepAlive) -> None:
304286
"""
305287
Send a message to the websocket connection.
306288
The message will be sent as a AgentV1KeepAlive.
307289
"""
308-
self._send_model(message or AgentV1KeepAlive(type="KeepAlive"))
290+
self._send_model(message)
309291

310292
def send_update_prompt(self, message: AgentV1UpdatePrompt) -> None:
311293
"""
@@ -337,7 +319,7 @@ def recv(self) -> V1SocketClientResponse:
337319
return data # type: ignore
338320
json_data = json.loads(data)
339321
try:
340-
return construct_type(type_=V1SocketClientResponse, object_=json_data) # type: ignore
322+
return construct_type(V1SocketClientResponse, json_data) # type: ignore
341323
except Exception:
342324
_logger.warning("Skipping unknown WebSocket message; update your SDK version to support new message types.")
343325
return json_data # type: ignore
@@ -354,4 +336,4 @@ def _send_model(self, data: typing.Any) -> None:
354336
"""
355337
Send a Pydantic model to the websocket connection.
356338
"""
357-
self._send(_sanitize_numeric_types(data.dict()))
339+
self._send(data.dict())

src/deepgram/listen/v1/socket_client.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import json
44
import logging
55
import typing
6+
from json.decoder import JSONDecodeError
67

8+
import websockets
79
import websockets.sync.connection as websockets_sync_connection
810
from ...core.events import EventEmitterMixin, EventType
911
from ...core.unchecked_base_model import construct_type
@@ -35,7 +37,7 @@ async def __aiter__(self):
3537
yield message
3638
else:
3739
try:
38-
yield construct_type(type_=V1SocketClientResponse, object_=json.loads(message)) # type: ignore
40+
yield construct_type(V1SocketClientResponse, json.loads(message)) # type: ignore
3941
except Exception:
4042
_logger.warning(
4143
"Skipping unknown WebSocket message; update your SDK version to support new message types."
@@ -60,14 +62,14 @@ async def start_listening(self):
6062
else:
6163
json_data = json.loads(raw_message)
6264
try:
63-
parsed = construct_type(type_=V1SocketClientResponse, object_=json_data) # type: ignore
65+
parsed = construct_type(V1SocketClientResponse, json_data) # type: ignore
6466
except Exception:
6567
_logger.warning(
6668
"Skipping unknown WebSocket message; update your SDK version to support new message types."
6769
)
6870
continue
6971
await self._emit_async(EventType.MESSAGE, parsed)
70-
except Exception as exc:
72+
except (websockets.WebSocketException, JSONDecodeError) as exc:
7173
await self._emit_async(EventType.ERROR, exc)
7274
finally:
7375
await self._emit_async(EventType.CLOSE, None)
@@ -79,26 +81,26 @@ async def send_media(self, message: bytes) -> None:
7981
"""
8082
await self._send(message)
8183

82-
async def send_finalize(self, message: typing.Optional[ListenV1Finalize] = None) -> None:
84+
async def send_finalize(self, message: ListenV1Finalize) -> None:
8385
"""
8486
Send a message to the websocket connection.
8587
The message will be sent as a ListenV1Finalize.
8688
"""
87-
await self._send_model(message or ListenV1Finalize(type="Finalize"))
89+
await self._send_model(message)
8890

89-
async def send_close_stream(self, message: typing.Optional[ListenV1CloseStream] = None) -> None:
91+
async def send_close_stream(self, message: ListenV1CloseStream) -> None:
9092
"""
9193
Send a message to the websocket connection.
9294
The message will be sent as a ListenV1CloseStream.
9395
"""
94-
await self._send_model(message or ListenV1CloseStream(type="CloseStream"))
96+
await self._send_model(message)
9597

96-
async def send_keep_alive(self, message: typing.Optional[ListenV1KeepAlive] = None) -> None:
98+
async def send_keep_alive(self, message: ListenV1KeepAlive) -> None:
9799
"""
98100
Send a message to the websocket connection.
99101
The message will be sent as a ListenV1KeepAlive.
100102
"""
101-
await self._send_model(message or ListenV1KeepAlive(type="KeepAlive"))
103+
await self._send_model(message)
102104

103105
async def recv(self) -> V1SocketClientResponse:
104106
"""
@@ -109,7 +111,7 @@ async def recv(self) -> V1SocketClientResponse:
109111
return data # type: ignore
110112
json_data = json.loads(data)
111113
try:
112-
return construct_type(type_=V1SocketClientResponse, object_=json_data) # type: ignore
114+
return construct_type(V1SocketClientResponse, json_data) # type: ignore
113115
except Exception:
114116
_logger.warning("Skipping unknown WebSocket message; update your SDK version to support new message types.")
115117
return json_data # type: ignore
@@ -140,7 +142,7 @@ def __iter__(self):
140142
yield message
141143
else:
142144
try:
143-
yield construct_type(type_=V1SocketClientResponse, object_=json.loads(message)) # type: ignore
145+
yield construct_type(V1SocketClientResponse, json.loads(message)) # type: ignore
144146
except Exception:
145147
_logger.warning(
146148
"Skipping unknown WebSocket message; update your SDK version to support new message types."
@@ -165,14 +167,14 @@ def start_listening(self):
165167
else:
166168
json_data = json.loads(raw_message)
167169
try:
168-
parsed = construct_type(type_=V1SocketClientResponse, object_=json_data) # type: ignore
170+
parsed = construct_type(V1SocketClientResponse, json_data) # type: ignore
169171
except Exception:
170172
_logger.warning(
171173
"Skipping unknown WebSocket message; update your SDK version to support new message types."
172174
)
173175
continue
174176
self._emit(EventType.MESSAGE, parsed)
175-
except Exception as exc:
177+
except (websockets.WebSocketException, JSONDecodeError) as exc:
176178
self._emit(EventType.ERROR, exc)
177179
finally:
178180
self._emit(EventType.CLOSE, None)
@@ -184,26 +186,26 @@ def send_media(self, message: bytes) -> None:
184186
"""
185187
self._send(message)
186188

187-
def send_finalize(self, message: typing.Optional[ListenV1Finalize] = None) -> None:
189+
def send_finalize(self, message: ListenV1Finalize) -> None:
188190
"""
189191
Send a message to the websocket connection.
190192
The message will be sent as a ListenV1Finalize.
191193
"""
192-
self._send_model(message or ListenV1Finalize(type="Finalize"))
194+
self._send_model(message)
193195

194-
def send_close_stream(self, message: typing.Optional[ListenV1CloseStream] = None) -> None:
196+
def send_close_stream(self, message: ListenV1CloseStream) -> None:
195197
"""
196198
Send a message to the websocket connection.
197199
The message will be sent as a ListenV1CloseStream.
198200
"""
199-
self._send_model(message or ListenV1CloseStream(type="CloseStream"))
201+
self._send_model(message)
200202

201-
def send_keep_alive(self, message: typing.Optional[ListenV1KeepAlive] = None) -> None:
203+
def send_keep_alive(self, message: ListenV1KeepAlive) -> None:
202204
"""
203205
Send a message to the websocket connection.
204206
The message will be sent as a ListenV1KeepAlive.
205207
"""
206-
self._send_model(message or ListenV1KeepAlive(type="KeepAlive"))
208+
self._send_model(message)
207209

208210
def recv(self) -> V1SocketClientResponse:
209211
"""
@@ -214,7 +216,7 @@ def recv(self) -> V1SocketClientResponse:
214216
return data # type: ignore
215217
json_data = json.loads(data)
216218
try:
217-
return construct_type(type_=V1SocketClientResponse, object_=json_data) # type: ignore
219+
return construct_type(V1SocketClientResponse, json_data) # type: ignore
218220
except Exception:
219221
_logger.warning("Skipping unknown WebSocket message; update your SDK version to support new message types.")
220222
return json_data # type: ignore

0 commit comments

Comments
 (0)