Module: OpenAI::Helpers::Realtime::Connections
- Included in:
- Resources::Realtime
- Defined in:
- lib/openai/helpers/realtime/resources/realtime_extension.rb
Overview
Ruby-native WebSocket entry point layered onto the generated Realtime resource. Generated HTTP accessors remain owned by the generated class.
Instance Method Summary collapse
-
#connect(model:, websocket_base_url: nil, request_options: nil, transport: nil, transport_options: {}, reconnect: false, max_reconnect_attempts: 5, max_queue_bytes: 0, on_reconnected: nil, &block) ⇒ Object
Open a server-side Realtime WebSocket.
-
#connect_to_call(call_id:, websocket_base_url: nil, request_options: nil, transport: nil, transport_options: {}, &block) ⇒ Object
Attach a server-side control WebSocket to an existing WebRTC or SIP call.
-
#connect_transcription(websocket_base_url: nil, request_options: nil, transport: nil, transport_options: {}, &block) ⇒ Object
Open a dedicated server-side Realtime transcription WebSocket.
Instance Method Details
#connect(model:, websocket_base_url: nil, request_options: nil, transport: nil, transport_options: {}, reconnect: false, max_reconnect_attempts: 5, max_queue_bytes: 0, on_reconnected: nil, &block) ⇒ Object
Open a server-side Realtime WebSocket. A block is required and the socket is closed on every exit path.
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 |
# File 'lib/openai/helpers/realtime/resources/realtime_extension.rb', line 11 def connect( model:, websocket_base_url: nil, request_options: nil, transport: nil, transport_options: {}, reconnect: false, max_reconnect_attempts: 5, max_queue_bytes: 0, on_reconnected: nil, &block ) raise ArgumentError, "A block is required to open a Realtime WebSocket." unless block unless reconnect == true || reconnect == false raise ArgumentError, "`reconnect` must be true or false." end OpenAI::Realtime::Recovery.( max_reconnect_attempts: max_reconnect_attempts, max_queue_bytes: max_queue_bytes, on_reconnected: on_reconnected ) if !reconnect && (max_queue_bytes.positive? || on_reconnected) raise ArgumentError, "Queueing and recovery callbacks require `reconnect: true`." end manager = OpenAI::Realtime::ConnectionManager.new( client: @client, query: {"model" => model}, websocket_base_url: websocket_base_url, transport: transport, request_options: , transport_options: ) return manager.open(&block) unless reconnect OpenAI::Realtime::Recovery .new( manager: manager, max_reconnect_attempts: max_reconnect_attempts, max_queue_bytes: max_queue_bytes, on_reconnected: on_reconnected ) .open(&block) end |
#connect_to_call(call_id:, websocket_base_url: nil, request_options: nil, transport: nil, transport_options: {}, &block) ⇒ Object
Attach a server-side control WebSocket to an existing WebRTC or SIP call.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/openai/helpers/realtime/resources/realtime_extension.rb', line 58 def connect_to_call( call_id:, websocket_base_url: nil, request_options: nil, transport: nil, transport_options: {}, &block ) raise ArgumentError, "A block is required to open a Realtime WebSocket." unless block unless call_id.is_a?(String) && !call_id.empty? raise ArgumentError, "`call_id` must be a non-empty String." end manager = OpenAI::Realtime::ConnectionManager.new( client: @client, query: {"call_id" => call_id}, websocket_base_url: websocket_base_url, transport: transport, request_options: , transport_options: , connection_class: OpenAI::Realtime::SidebandConnection ) manager.open(&block) end |
#connect_transcription(websocket_base_url: nil, request_options: nil, transport: nil, transport_options: {}, &block) ⇒ Object
Open a dedicated server-side Realtime transcription WebSocket. The transcription model is selected in the subsequent session update.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/openai/helpers/realtime/resources/realtime_extension.rb', line 85 def connect_transcription( websocket_base_url: nil, request_options: nil, transport: nil, transport_options: {}, &block ) raise ArgumentError, "A block is required to open a Realtime WebSocket." unless block manager = OpenAI::Realtime::ConnectionManager.new( client: @client, query: {"intent" => "transcription"}, websocket_base_url: websocket_base_url, transport: transport, request_options: , transport_options: ) manager.open(&block) end |