Skip to content

Commit 5f1f5dc

Browse files
bgotthold-aaiAssemblyAI
andauthored
chore: sync sdk code with DeepLearning repo (#192)
Co-authored-by: AssemblyAI <engineering.sdk@assemblyai.com>
1 parent 9be6586 commit 5f1f5dc

4 files changed

Lines changed: 28 additions & 1 deletion

File tree

assemblyai/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.61.1"
1+
__version__ = "0.62.0"

assemblyai/streaming/v3/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
StreamingSessionParameters,
1515
TerminationEvent,
1616
TurnEvent,
17+
WarningEvent,
1718
Word,
1819
)
1920

@@ -33,5 +34,6 @@
3334
"StreamingSessionParameters",
3435
"TerminationEvent",
3536
"TurnEvent",
37+
"WarningEvent",
3638
"Word",
3739
]

assemblyai/streaming/v3/client.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
TerminationEvent,
3232
TurnEvent,
3333
UpdateConfiguration,
34+
WarningEvent,
3435
)
3536

3637
logger = logging.getLogger(__name__)
@@ -220,6 +221,8 @@ def _read_message(self) -> None:
220221

221222
if isinstance(message, ErrorEvent):
222223
self._handle_error(message)
224+
elif isinstance(message, WarningEvent):
225+
self._handle_warning(message)
223226
elif message:
224227
self._handle_message(message)
225228
else:
@@ -250,6 +253,10 @@ def _parse_message(self, data: Dict[str, Any]) -> Optional[EventMessage]:
250253
return SpeechStartedEvent.model_validate(data)
251254
elif event_type == StreamingEvents.LLMGatewayResponse:
252255
return LLMGatewayResponseEvent.model_validate(data)
256+
elif event_type == StreamingEvents.Error:
257+
return ErrorEvent.model_validate(data)
258+
elif event_type == StreamingEvents.Warning:
259+
return WarningEvent.model_validate(data)
253260
else:
254261
return None
255262
elif "error" in data:
@@ -267,6 +274,13 @@ def _parse_event_type(message_type: Optional[Any]) -> Optional[StreamingEvents]:
267274
except KeyError:
268275
return None
269276

277+
def _handle_warning(self, warning: WarningEvent):
278+
logger.warning(
279+
"Streaming warning (code=%s): %s", warning.warning_code, warning.warning
280+
)
281+
for handler in self._handlers[StreamingEvents.Warning]:
282+
handler(self, warning)
283+
270284
def _handle_error(
271285
self,
272286
error: Union[
@@ -291,6 +305,7 @@ def _parse_error(
291305
if isinstance(error, ErrorEvent):
292306
return StreamingError(
293307
message=error.error,
308+
code=error.error_code,
294309
)
295310
elif isinstance(error, websockets.exceptions.ConnectionClosed):
296311
if (

assemblyai/streaming/v3/models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,17 @@ class SpeechStartedEvent(BaseModel):
5555

5656

5757
class ErrorEvent(BaseModel):
58+
type: Literal["Error"] = "Error"
59+
error_code: Optional[int] = None
5860
error: str
5961

6062

63+
class WarningEvent(BaseModel):
64+
type: Literal["Warning"] = "Warning"
65+
warning_code: int
66+
warning: str
67+
68+
6169
class LLMGatewayResponseEvent(BaseModel):
6270
type: Literal["LLMGatewayResponse"] = "LLMGatewayResponse"
6371
turn_order: int
@@ -71,6 +79,7 @@ class LLMGatewayResponseEvent(BaseModel):
7179
TurnEvent,
7280
SpeechStartedEvent,
7381
ErrorEvent,
82+
WarningEvent,
7483
LLMGatewayResponseEvent,
7584
]
7685

@@ -201,4 +210,5 @@ class StreamingEvents(Enum):
201210
Turn = "Turn"
202211
SpeechStarted = "SpeechStarted"
203212
Error = "Error"
213+
Warning = "Warning"
204214
LLMGatewayResponse = "LLMGatewayResponse"

0 commit comments

Comments
 (0)