Module: Anthropic::Internal::Type::BaseStream Private

Includes:
Enumerable
Included in:
Helpers::Streaming::MessageStream, JsonLStream, Stream
Defined in:
lib/anthropic/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.

See Also:

Generic:

  • Elem

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#headersHash{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.

Returns:

  • (Hash{String=>String})


20
21
22
# File 'lib/anthropic/internal/type/base_stream.rb', line 20

def headers
  @headers
end

#statusInteger (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.

Returns:

  • (Integer)


17
18
19
# File 'lib/anthropic/internal/type/base_stream.rb', line 17

def status
  @status
end

Instance Method Details

#closevoid

This method returns an undefined value.



25
# File 'lib/anthropic/internal/type/base_stream.rb', line 25

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

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

This method returns an undefined value.

Parameters:

  • blk (Proc)

Yield Parameters:

  • (generic<Elem>)


38
39
40
41
42
43
# File 'lib/anthropic/internal/type/base_stream.rb', line 38

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:, headers:, response:, unwrap:, stream:) ⇒ 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.

Parameters:

  • model (Class, Anthropic::Internal::Type::Converter)
  • url (URI::Generic)
  • status (Integer)
  • headers (Hash{String=>String})
  • response (Net::HTTPResponse)
  • unwrap (Symbol, Integer, Array<Symbol, Integer>, Proc)
  • stream (Enumerable<Object>)


61
62
63
64
65
66
67
68
69
70
# File 'lib/anthropic/internal/type/base_stream.rb', line 61

def initialize(model:, url:, status:, headers:, response:, unwrap:, stream:)
  @model = model
  @url = url
  @status = status
  @headers = headers
  @response = response
  @unwrap = unwrap
  @stream = stream
  @iterator = iterator
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)


75
76
77
78
79
# File 'lib/anthropic/internal/type/base_stream.rb', line 75

def inspect
  model = Anthropic::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>>)


48
# File 'lib/anthropic/internal/type/base_stream.rb', line 48

def to_enum = @iterator