OpenAIRealtimeClient

class OpenAIRealtimeClient()

(Experimental) Client for OpenAI Realtime API.

__init__

def __init__(agent: "RealtimeAgent", audio_adapter: "RealtimeObserver",
             function_observer: "FunctionObserver") -> None

(Experimental) Client for OpenAI Realtime API.

Arguments:

  • agent RealtimeAgent - The agent that the client is associated with.
  • audio_adapter RealtimeObserver - The audio adapter for the client.
  • function_observer FunctionObserver - The function observer for the client.

openai_ws

@property
def openai_ws() -> ClientConnection

Get the OpenAI WebSocket connection.

register

def register(observer: "RealtimeObserver") -> None

Register an observer to the client.

notify_observers

async def notify_observers(message: dict[str, Any]) -> None

Notify all observers of a message from the OpenAI Realtime API.

Arguments:

  • message dict[str, Any] - The message from the OpenAI Realtime API.

function_result

async def function_result(call_id: str, result: str) -> None

Send the result of a function call to the OpenAI Realtime API.

Arguments:

  • call_id str - The ID of the function call.
  • result str - The result of the function call.

send_text

async def send_text(*, role: str, text: str) -> None

Send a text message to the OpenAI Realtime API.

Arguments:

  • role str - The role of the message.
  • text str - The text of the message.

initialize_session

async def initialize_session() -> None

Control initial session with OpenAI.

session_update

async def session_update(session_options: dict[str, Any]) -> None

Send a session update to the OpenAI Realtime API.

Arguments:

  • session_options dict[str, Any] - The session options to update.

run

async def run() -> None

Run the client.