-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathmodel_events.py
More file actions
203 lines (127 loc) · 4.42 KB
/
model_events.py
File metadata and controls
203 lines (127 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
from __future__ import annotations
from dataclasses import dataclass
from typing import Any, Literal, TypeAlias
from .items import RealtimeItem
RealtimeConnectionStatus: TypeAlias = Literal["connecting", "connected", "disconnected"]
@dataclass
class RealtimeModelErrorEvent:
"""Represents a transport‑layer error."""
error: Any
type: Literal["error"] = "error"
@dataclass
class RealtimeModelToolCallEvent:
"""Model attempted a tool/function call."""
name: str
call_id: str
arguments: str
id: str | None = None
previous_item_id: str | None = None
response_id: str | None = None
"""The ID of the model response that produced this tool call."""
type: Literal["function_call"] = "function_call"
@dataclass
class RealtimeModelAudioEvent:
"""Raw audio bytes emitted by the model."""
data: bytes
response_id: str
item_id: str
"""The ID of the item containing audio."""
content_index: int
"""The index of the audio content in `item.content`"""
type: Literal["audio"] = "audio"
@dataclass
class RealtimeModelAudioInterruptedEvent:
"""Audio interrupted."""
item_id: str
"""The ID of the item containing audio."""
content_index: int
"""The index of the audio content in `item.content`"""
type: Literal["audio_interrupted"] = "audio_interrupted"
@dataclass
class RealtimeModelAudioDoneEvent:
"""Audio done."""
item_id: str
"""The ID of the item containing audio."""
content_index: int
"""The index of the audio content in `item.content`"""
type: Literal["audio_done"] = "audio_done"
@dataclass
class RealtimeModelInputAudioTranscriptionCompletedEvent:
"""Input audio transcription completed."""
item_id: str
transcript: str
type: Literal["input_audio_transcription_completed"] = "input_audio_transcription_completed"
@dataclass
class RealtimeModelInputAudioTimeoutTriggeredEvent:
"""Input audio timeout triggered."""
item_id: str
audio_start_ms: int
audio_end_ms: int
type: Literal["input_audio_timeout_triggered"] = "input_audio_timeout_triggered"
@dataclass
class RealtimeModelTranscriptDeltaEvent:
"""Partial transcript update."""
item_id: str
delta: str
response_id: str
type: Literal["transcript_delta"] = "transcript_delta"
@dataclass
class RealtimeModelItemUpdatedEvent:
"""Item added to the history or updated."""
item: RealtimeItem
type: Literal["item_updated"] = "item_updated"
@dataclass
class RealtimeModelItemDeletedEvent:
"""Item deleted from the history."""
item_id: str
type: Literal["item_deleted"] = "item_deleted"
@dataclass
class RealtimeModelConnectionStatusEvent:
"""Connection status changed."""
status: RealtimeConnectionStatus
type: Literal["connection_status"] = "connection_status"
@dataclass
class RealtimeModelTurnStartedEvent:
"""Triggered when the model starts generating a response for a turn."""
type: Literal["turn_started"] = "turn_started"
@dataclass
class RealtimeModelTurnEndedEvent:
"""Triggered when the model finishes generating a response for a turn."""
response_id: str | None = None
"""The ID of the model response that just finished, if available."""
type: Literal["turn_ended"] = "turn_ended"
@dataclass
class RealtimeModelOtherEvent:
"""Used as a catchall for vendor-specific events."""
data: Any
type: Literal["other"] = "other"
@dataclass
class RealtimeModelExceptionEvent:
"""Exception occurred during model operation."""
exception: Exception
context: str | None = None
type: Literal["exception"] = "exception"
@dataclass
class RealtimeModelRawServerEvent:
"""Raw events forwarded from the server."""
data: Any
type: Literal["raw_server_event"] = "raw_server_event"
# TODO (rm) Add usage events
RealtimeModelEvent: TypeAlias = (
RealtimeModelErrorEvent
| RealtimeModelToolCallEvent
| RealtimeModelAudioEvent
| RealtimeModelAudioInterruptedEvent
| RealtimeModelAudioDoneEvent
| RealtimeModelInputAudioTimeoutTriggeredEvent
| RealtimeModelInputAudioTranscriptionCompletedEvent
| RealtimeModelTranscriptDeltaEvent
| RealtimeModelItemUpdatedEvent
| RealtimeModelItemDeletedEvent
| RealtimeModelConnectionStatusEvent
| RealtimeModelTurnStartedEvent
| RealtimeModelTurnEndedEvent
| RealtimeModelOtherEvent
| RealtimeModelExceptionEvent
| RealtimeModelRawServerEvent
)