Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions examples/realtime/push_to_talk_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
from textual.containers import Container

from openai import AsyncOpenAI
from openai.types.realtime.session import Session
from openai.resources.realtime.realtime import AsyncRealtimeConnection
from openai.types.realtime.session_update_event import Session


class SessionDisplay(Static):
Expand Down Expand Up @@ -176,8 +176,9 @@ async def handle_realtime_connection(self) -> None:
if event.type == "session.created":
self.session = event.session
session_display = self.query_one(SessionDisplay)
assert event.session.id is not None
session_display.session_id = event.session.id
# `id` exists in the server response but is currently missing from generated type definitions.
assert event.session.id is not None # type: ignore[attr-defined]
session_display.session_id = event.session.id # type: ignore[attr-defined]
continue

if event.type == "session.updated":
Expand Down Expand Up @@ -272,7 +273,7 @@ async def on_key(self, event: events.Key) -> None:
self.should_send_audio.clear()
status_indicator.is_recording = False

if self.session and self.session.turn_detection is None:
if self.session and hasattr(self.session, "turn_detection") and self.session.turn_detection is None:
# The default in the API is that the model will automatically detect when the user has
# stopped talking and then start responding itself.
#
Expand Down