Module: OpenAI::Internal::Type::BaseStream Private
- Includes:
- Enumerable, Enumerable[Elem]
- 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
- #close ⇒ void
- #each(&blk) {|, arg0| ... } ⇒ void
- #initialize(model:, url:, response_metadata:, response:, unwrap:, stream:) ⇒ Object private
- #inspect ⇒ String private
-
#observe(context:, response:) ⇒ self
private
Attach request lifecycle logging without changing the stream's identity.
- #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.
27 28 29 |
# File 'lib/openai/internal/type/base_stream.rb', line 27 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
#close ⇒ void
This method returns an undefined value.
32 |
# File 'lib/openai/internal/type/base_stream.rb', line 32 def close = OpenAI::Internal::Util.close_fused!(@iterator) |
#each(&blk) {|, arg0| ... } ⇒ void
This method returns an undefined value.
72 73 74 75 76 77 |
# File 'lib/openai/internal/type/base_stream.rb', line 72 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:) ⇒ 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.
94 95 96 97 98 99 100 101 102 |
# File 'lib/openai/internal/type/base_stream.rb', line 94 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.
107 108 109 110 111 |
# File 'lib/openai/internal/type/base_stream.rb', line 107 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.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/openai/internal/type/base_stream.rb', line 41 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 |
#to_enum ⇒ Enumerator<generic<Elem>> Also known as: enum_for
82 |
# File 'lib/openai/internal/type/base_stream.rb', line 82 def to_enum = @iterator |