Class: OpenAI::WebSocket::TypedConnection Private
- Inherits:
-
Connection
- Object
- Connection
- OpenAI::WebSocket::TypedConnection
- Includes:
- Enumerable, GuardedConnection, Protocol
- Defined in:
- lib/openai/helpers/websocket/typed_connection.rb,
sig/openai/helpers/websocket.rbs
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Shared event codec for generated bindings and specialized product facades.
Direct Known Subclasses
Instance Attribute Summary collapse
- #url ⇒ URI::Generic readonly private
Instance Method Summary collapse
- #close ⇒ void private
- #closed? ⇒ Boolean private
- #each ⇒ Enumerator[Elem, self], { (Elem) -> void } -> self private
-
#initialize(socket:, url:, client_event:, server_event:) ⇒ TypedConnection
constructor
private
A new instance of TypedConnection.
- #parse_event(data) ⇒ Object private
- #receive ⇒ Elem? private
- #send_event(event) ⇒ void private
Methods included from GuardedConnection
Methods inherited from Connection
#abort, #receive_raw, #send_raw
Constructor Details
#initialize(socket:, url:, client_event:, server_event:) ⇒ TypedConnection
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of TypedConnection.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/openai/helpers/websocket/typed_connection.rb', line 12 def initialize(socket:, url:, client_event:, server_event:) super(socket: socket, url: url) @client_event = client_event @server_event = server_event variants = client_event.respond_to?(:variants) ? client_event.variants : [client_event] @client_event_types = variants.map do |variant| variant.fields.dig(:type, :type) if variant.respond_to?(:fields) end variants = server_event.respond_to?(:variants) ? server_event.variants : [server_event] @server_event_types = variants.filter_map do |variant| type = variant&.fields&.dig(:type, :type) [type, variant] if type end end |
Instance Attribute Details
#url ⇒ URI::Generic (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
48 49 50 |
# File 'sig/openai/helpers/websocket.rbs', line 48 def url @url end |
Instance Method Details
#close ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
54 |
# File 'sig/openai/helpers/websocket.rbs', line 54
def close: (?code: Integer, ?reason: String) -> void
|
#closed? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
55 |
# File 'sig/openai/helpers/websocket.rbs', line 55
def closed?: -> bool
|
#each ⇒ Enumerator[Elem, self], { (Elem) -> void } -> self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 |
# File 'sig/openai/helpers/websocket.rbs', line 53
def each: -> Enumerator[Elem, self] | { (Elem) -> void } -> self
|
#parse_event(data) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/openai/helpers/websocket/typed_connection.rb', line 50 def parse_event(data) parsed = parse_json(data) type = event_type(parsed, message: "WebSocket server event must be an object with a string type") _, model = @server_event_types.find { |event_type,| event_type === type.to_sym } return unknown_server_event(parsed) unless model event = coerce(@server_event, parsed) validate_wire_field_names!(event, parsed) rescue StandardError, SystemStackError raise protocol_error, cause: nil end |
#receive ⇒ Elem?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
49 |
# File 'sig/openai/helpers/websocket.rbs', line 49
def receive: -> Elem?
|
#send_event(event) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
28 29 30 |
# File 'lib/openai/helpers/websocket/typed_connection.rb', line 28 def send_event(event) send_raw(encode_client_event(event)) end |