Class: LLM::Gemini::StreamParser

Inherits:
Object
  • Object
show all
Defined in:
lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/stream_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ LLM::Gemini::StreamParser

Parameters:

  • io (#<<)

    An IO-like object



15
16
17
18
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/stream_parser.rb', line 15

def initialize(io)
  @body = LLM::Object.from_hash({candidates: []})
  @io = io
end

Instance Attribute Details

#bodyLLM::Object (readonly)

Returns the fully constructed response body

Returns:



10
11
12
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/stream_parser.rb', line 10

def body
  @body
end

Instance Method Details

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

Parameters:

  • chunk (Hash)

Returns:



23
24
25
# File 'lib/llm/shell/internal/llm.rb/lib/llm/providers/gemini/stream_parser.rb', line 23

def parse!(chunk)
  tap { merge_chunk!(LLM::Object.from_hash(chunk)) }
end