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

Includes:
Enumerable, Enumerable[Elem]
Included in:
Helpers::Streaming::MessageStream, JsonLStream, Stream
Defined in:
lib/anthropic/internal/type/base_stream.rb,
sig/anthropic/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

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.



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

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

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

This method returns an undefined value.

Parameters:

  • blk (Proc)

Yields:

Yield Parameters:

  • (generic<Elem>)
  • arg0 (Elem)

Yield Returns:

  • (void)


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

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:) ⇒ 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:

  • 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>)


71
72
73
74
75
76
77
78
79
80
# File 'lib/anthropic/internal/type/base_stream.rb', line 71

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)


85
86
87
88
89
# File 'lib/anthropic/internal/type/base_stream.rb', line 85

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

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

#request_idString?

Returns:

  • (String, nil)


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

def request_id = headers["request-id"]

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

Returns:

  • (Enumerator<generic<Elem>>)


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

def to_enum = @iterator

#workspace_idString?

Returns:

  • (String, nil)


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

def workspace_id = headers["anthropic-workspace-id"]