Class: LLM::Anthropic::StreamParser

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/providers/anthropic/stream_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ LLM::Anthropic::StreamParser

Parameters:

  • stream (#<<, LLM::Stream)

    A stream sink that implements #<< or the Stream interface



16
17
18
19
# File 'lib/llm/providers/anthropic/stream_parser.rb', line 16

def initialize(stream)
  @body = {"role" => "assistant", "content" => []}
  @stream = stream
end

Instance Attribute Details

#bodyHash (readonly)

Returns the fully constructed response body

Returns:

  • (Hash)


10
11
12
# File 'lib/llm/providers/anthropic/stream_parser.rb', line 10

def body
  @body
end

Instance Method Details

#freevoid

This method returns an undefined value.

Frees internal parser state used during streaming.



31
32
# File 'lib/llm/providers/anthropic/stream_parser.rb', line 31

def free
end

#parse!(chunk) ⇒ LLM::Anthropic::StreamParser

Parameters:

  • chunk (Hash)

Returns:



24
25
26
# File 'lib/llm/providers/anthropic/stream_parser.rb', line 24

def parse!(chunk)
  tap { merge!(chunk) }
end