Module: RubyLLM::Providers::Gemini::Streaming

Included in:
RubyLLM::Providers::Gemini
Defined in:
lib/ruby_llm/providers/gemini/streaming.rb

Overview

Streaming methods for the Gemini API implementation

Instance Method Summary collapse

Instance Method Details

#build_chunk(data) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ruby_llm/providers/gemini/streaming.rb', line 12

def build_chunk(data)
  parts = data.dig('candidates', 0, 'content', 'parts') || []

  Chunk.new(
    role: :assistant,
    model_id: extract_model_id(data),
    content: extract_text_content(parts),
    thinking: Thinking.build(
      text: extract_thought_content(parts),
      signature: extract_thought_signature(parts)
    ),
    input_tokens: extract_input_tokens(data),
    output_tokens: extract_output_tokens(data),
    thinking_tokens: data.dig('usageMetadata', 'thoughtsTokenCount'),
    tool_calls: extract_tool_calls(data)
  )
end

#stream_urlObject



8
9
10
# File 'lib/ruby_llm/providers/gemini/streaming.rb', line 8

def stream_url
  "models/#{@model}:streamGenerateContent?alt=sse"
end