Skip to content

Commit d02e20f

Browse files
committed
fix(sdk/python): add model_dump_json compatibility
1 parent fdccb03 commit d02e20f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

assemblyai/streaming/v3/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ def _dump_model(model: BaseModel):
4747
return model.dict(exclude_none=True)
4848

4949

50+
def _dump_model_json(model: BaseModel):
51+
if hasattr(model, "model_dump_json"):
52+
return model.model_dump_json(exclude_none=True)
53+
return model.json(exclude_none=True)
54+
55+
5056
class StreamingClient:
5157
def __init__(self, options: StreamingClientOptions):
5258
self._options = options
@@ -132,7 +138,7 @@ def _write_message(self) -> None:
132138
if isinstance(data, bytes):
133139
self._websocket.send(data)
134140
elif isinstance(data, BaseModel):
135-
self._websocket.send(json.dumps(data))
141+
self._websocket.send(_dump_model_json(data))
136142
else:
137143
raise ValueError(f"Attempted to send invalid message: {type(data)}")
138144
except websockets.exceptions.ConnectionClosed as exc:

0 commit comments

Comments
 (0)