Skip to content

Commit

Permalink
fix: emit error from realtime api (#1200)
Browse files Browse the repository at this point in the history
  • Loading branch information
longcw authored Dec 11, 2024
1 parent 6b4e903 commit 0e8a13d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eleven-pianos-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"livekit-plugins-openai": patch
---

emit error event for realtime model
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
InputTranscriptionFailed,
InputTranscriptionOptions,
RealtimeContent,
RealtimeError,
RealtimeModel,
RealtimeOutput,
RealtimeResponse,
Expand All @@ -23,6 +24,7 @@
"RealtimeToolCall",
"RealtimeSession",
"RealtimeModel",
"RealtimeError",
"ServerVadOptions",
"InputTranscriptionOptions",
"ConversationItemCreated",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0e8a13d

Please sign in to comment.