File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+
5056class 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 :
You can’t perform that action at this time.
0 commit comments