diff --git a/.changeset/eleven-pianos-train.md b/.changeset/eleven-pianos-train.md new file mode 100644 index 000000000..d360f5af0 --- /dev/null +++ b/.changeset/eleven-pianos-train.md @@ -0,0 +1,5 @@ +--- +"livekit-plugins-openai": patch +--- + +emit error event for realtime model diff --git a/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/__init__.py b/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/__init__.py index 6852c3bf6..ac9b866d6 100644 --- a/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/__init__.py +++ b/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/__init__.py @@ -6,6 +6,7 @@ InputTranscriptionFailed, InputTranscriptionOptions, RealtimeContent, + RealtimeError, RealtimeModel, RealtimeOutput, RealtimeResponse, @@ -23,6 +24,7 @@ "RealtimeToolCall", "RealtimeSession", "RealtimeModel", + "RealtimeError", "ServerVadOptions", "InputTranscriptionOptions", "ConversationItemCreated", diff --git a/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/realtime_model.py b/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/realtime_model.py index 0b5243728..5053bb949 100644 --- a/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/realtime_model.py +++ b/livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/realtime_model.py @@ -6,7 +6,7 @@ import time from copy import deepcopy from dataclasses import dataclass -from typing import AsyncIterable, Literal, Union, cast, overload +from typing import AsyncIterable, Literal, Optional, Union, cast, overload from urllib.parse import urlencode import aiohttp @@ -141,6 +141,15 @@ class InputTranscriptionOptions: model: api_proto.InputTranscriptionModel | str +@dataclass +class RealtimeError: + event_id: str + type: str + message: str + code: Optional[str] + param: Optional[str] + + @dataclass class _ModelOptions: model: str | None @@ -1079,6 +1088,17 @@ def _handle_error(self, error: api_proto.ServerEvent.Error): error, extra=self.logging_extra(), ) + error_content = error["error"] + self.emit( + "error", + RealtimeError( + event_id=error["event_id"], + type=error_content["type"], + message=error_content["message"], + code=error_content.get("code"), + param=error_content.get("param"), + ), + ) def _handle_input_audio_buffer_speech_started( self, speech_started: api_proto.ServerEvent.InputAudioBufferSpeechStarted