Module: OpenAI::Internal::Type::BaseStream Private
- Includes:
- Enumerable
- Defined in:
- lib/openai/internal/type/base_stream.rb,
sig/openai/internal/type/base_stream.rbs
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
This module provides a base implementation for streaming responses in the SDK.
Instance Attribute Summary collapse
- #headers ⇒ Hash{String=>String} readonly private
-
#last_response ⇒ OpenAI::ResponseMetadata
readonly
Metadata from the HTTP response that opened this stream.
- #status ⇒ Integer readonly private
Instance Method Summary collapse
-
#_request_id ⇒ String?
The ID of the API request, returned via the x-request-id response header.
- #close ⇒ void
- #each(&blk) {|, arg0| ... } ⇒ void
-
#initialize(model:, url:, response_metadata:, response:, unwrap:, stream:) ⇒ BaseStream
private
A new instance of BaseStream.
- #inspect ⇒ String private
-
#observe(context:, response:) ⇒ self
private
Attach request lifecycle logging without changing the stream's identity.
-
#set_stream_mode(mode) ⇒ self
private
Configure event delivery without changing custom stream initializers.
- #to_enum ⇒ Enumerator<generic<Elem>> (also: #enum_for)
Instance Attribute Details
#headers ⇒ Hash{String=>String} (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.
20 |
# File 'lib/openai/internal/type/base_stream.rb', line 20 def headers = last_response.headers |
#last_response ⇒ OpenAI::ResponseMetadata (readonly)
Metadata from the HTTP response that opened this stream.
35 36 37 |
# File 'lib/openai/internal/type/base_stream.rb', line 35 def last_response @last_response end |
#status ⇒ Integer (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.
17 |
# File 'lib/openai/internal/type/base_stream.rb', line 17 def status = last_response.status |
Instance Method Details
#_request_id ⇒ String?
The ID of the API request, returned via the x-request-id response header.
28 |
# File 'lib/openai/internal/type/base_stream.rb', line 28 def _request_id = last_response.request_id |
#close ⇒ void
This method returns an undefined value.
40 |
# File 'lib/openai/internal/type/base_stream.rb', line 40 def close = OpenAI::Internal::Util.close_fused!(@iterator) |
#each(&blk) {|, arg0| ... } ⇒ void
This method returns an undefined value.
91 92 93 94 95 96 97 |
# File 'lib/openai/internal/type/base_stream.rb', line 91 def each(&blk) unless block_given? raise ArgumentError.new("A block must be given to ##{__method__}") end @iterator.each(&blk) end |
#initialize(model:, url:, response_metadata:, response:, unwrap:, stream:) ⇒ BaseStream
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 BaseStream.
114 115 116 117 118 119 120 121 122 |
# File 'lib/openai/internal/type/base_stream.rb', line 114 def initialize(model:, url:, response_metadata:, response:, unwrap:, stream:) @model = model @url = url @last_response = @response = response @unwrap = unwrap @stream = stream @iterator = iterator end |
#inspect ⇒ String
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.
127 128 129 130 131 |
# File 'lib/openai/internal/type/base_stream.rb', line 127 def inspect model = OpenAI::Internal::Type::Converter.inspect(@model, depth: 1) "#<#{self.class}[#{model}]:0x#{object_id.to_s(16)}>" end |
#observe(context:, response:) ⇒ 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.
Attach request lifecycle logging without changing the stream's identity.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/openai/internal/type/base_stream.rb', line 59 def observe(context:, response:) source = @iterator @iterator = OpenAI::Internal::Util.chain_fused(source) do |yielder| loop do event = begin source.next rescue StopIteration context.completed(response) break rescue StandardError => e context.request_failed(e) raise end yielder << event end end self end |
#set_stream_mode(mode) ⇒ 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.
Configure event delivery without changing custom stream initializers.
47 48 49 50 |
# File 'lib/openai/internal/type/base_stream.rb', line 47 def set_stream_mode(mode) @stream_mode = mode self end |
#to_enum ⇒ Enumerator<generic<Elem>> Also known as: enum_for
102 |
# File 'lib/openai/internal/type/base_stream.rb', line 102 def to_enum = @iterator |