Module: OpenAI::Internal::Type::BaseStream Private

Includes:
Enumerable
Included in:
Stream
Defined in:
lib/openai/internal/type/base_stream.rb

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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defer_closing(stream) ⇒ Proc

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.

Attempt to close the underlying transport when the stream itself is garbage collected.

This should not be relied upon for resource clean up, as the garbage collector is not guaranteed to run.

Parameters:

  • stream (Enumerable<Object>)

Returns:

  • (Proc)

See Also:



28
# File 'lib/openai/internal/type/base_stream.rb', line 28

def defer_closing(stream) = ->(_id) { OpenAI::Internal::Util.close_fused!(stream) }

Instance Method Details

#closevoid

This method returns an undefined value.



34
# File 'lib/openai/internal/type/base_stream.rb', line 34

def close = OpenAI::Internal::Util.close_fused!(@iterator)

#each(&blk) {|| ... } ⇒ void

This method returns an undefined value.

Parameters:

  • blk (Proc)

Yield Parameters:

  • (generic<Elem>)


47
48
49
50
51
52
# File 'lib/openai/internal/type/base_stream.rb', line 47

def each(&blk)
  unless block_given?
    raise ArgumentError.new("A block must be given to ##{__method__}")
  end
  @iterator.each(&blk)
end

#initialize(model:, url:, status:, response:, 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.

Parameters:



68
69
70
71
72
73
74
75
76
77
# File 'lib/openai/internal/type/base_stream.rb', line 68

def initialize(model:, url:, status:, response:, stream:)
  @model = model
  @url = url
  @status = status
  @response = response
  @stream = stream
  @iterator = iterator

  ObjectSpace.define_finalizer(self, OpenAI::Internal::Type::BaseStream.defer_closing(@stream))
end

#inspectString

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:

  • (String)


82
83
84
85
86
# File 'lib/openai/internal/type/base_stream.rb', line 82

def inspect
  model = OpenAI::Internal::Type::Converter.inspect(@model, depth: 1)

  "#<#{self.class}[#{model}]:0x#{object_id.to_s(16)}>"
end

#to_enumEnumerator<generic<Elem>> Also known as: enum_for

Returns:

  • (Enumerator<generic<Elem>>)


57
# File 'lib/openai/internal/type/base_stream.rb', line 57

def to_enum = @iterator