Skip to main content

Python middlewares over the WebSocket of OpenAI Realtime API.

Project description

OpenAI Realtime API Python Utils

If you want to base your application/agent on OpenAI's realtime api, but:

then this package is for you.

Example

with hook_handlers(
    connection, 
    server_event_handlers = [
        track_config.server_event_handler,  # views session.updated
        track_conversation.server_event_handler,    # views various events
        *iap_server_handlers,   # views e.g. response.output_audio.delta
        stream_mic.server_event_handler,    # views session.updated
        print_events.server_event_handler, # views all events
        f, 
    ], 
    client_event_handlers = [
        middlewares.GiveClientEventId().client_event_handler, # alter all events without ID
        track_config.client_event_handler,  # views session.update
        track_conversation.client_event_handler,    # views various events
        print_events.client_event_handler, # views all events
    ],
) as (keep_receiving, send):
    iap_register_send_with_handlers(send)   # needs to send interrupt events
    stream_mic.register_send_with_handlers(send)    # needs to send audio input
    
    asyncio.create_task(keep_receiving())
...

Utilities & Middlewares

  • openai_realtime_api_utils.hook_handlers: run a session with your handlers.
  • openai_realtime_api_utils.middlewares
    • .TrackConfig: Keep track of session config.
    • .TrackConversation: Client-side representation of the conversation(s), synced by events.
    • .GiveClientEventId: Auto-fill client event id.
    • .Interrupt: The user may interrupt assistant speech.
    • .AudioPlayer: Host system audio playback.
    • .interruptable_audio_player: .Interrupt and .AudioPlayer in gift wraps.
    • .StreamMic: Host system audio capture.
    • .PrintEvents: Print events for debug.

Style

  • Functional programming.
  • Dependency injection.
  • Middleware event handlers.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openai_realtime_api_utils-0.1.2.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openai_realtime_api_utils-0.1.2-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file openai_realtime_api_utils-0.1.2.tar.gz.

File metadata

File hashes

Hashes for openai_realtime_api_utils-0.1.2.tar.gz
Algorithm Hash digest
SHA256 221615a196a54aed92afd09a957464195830640bc1fcd0b2592372b680a4e45a
MD5 080ca3ca065b935a26a6b855921f9d62
BLAKE2b-256 7c2b003e37d2bb31c9266f2cbd5bd6f5ecdc0e4df5261c354d2a7a3b84cdd52c

See more details on using hashes here.

File details

Details for the file openai_realtime_api_utils-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for openai_realtime_api_utils-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1495bb8213dbbd7ad0d59337db5c2daf39d86a663cf830262f05d188a41de9dd
MD5 71f4ce8567e3b4d9cd0f959ee3a66479
BLAKE2b-256 70385e355508346ab2ce3011c0c6d6d88ea2efa0a5c8d2b4a96fdf44be233531

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page