Class: LLM::Google::StreamParser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Parameters:

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

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



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

def initialize(stream)
  @body = {"candidates" => []}
  @stream = stream
  @emits = {tools: []}
end

Instance Attribute Details

#bodyHash (readonly)

Returns the fully constructed response body

Returns:

  • (Hash)


10
11
12
# File 'lib/llm/providers/google/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.



32
33
34
# File 'lib/llm/providers/google/stream_parser.rb', line 32

def free
  @emits.clear
end

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

Parameters:

  • chunk (Hash)

Returns:



25
26
27
# File 'lib/llm/providers/google/stream_parser.rb', line 25

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