Class: RubyLLM::Protocols::Converse::ThinkingStream

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/protocols/converse/thinking_stream.rb

Overview

:nodoc: all

Instance Method Summary collapse

Constructor Details

#initializeThinkingStream

Returns a new instance of ThinkingStream.



9
10
11
# File 'lib/ruby_llm/protocols/converse/thinking_stream.rb', line 9

def initialize
  @blocks = {}
end

Instance Method Details

#add(event) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruby_llm/protocols/converse/thinking_stream.rb', line 13

def add(event)
  @blocks.clear if event.key?('messageStart')
  part = event['contentBlockStart'] || event['contentBlockDelta'] || event
  index = part['contentBlockIndex']
  return if index.nil?

  start = part.dig('start', 'reasoningContent')
  @blocks[index] = Support::Utils.deep_dup(start) if start
  delta = part.dig('delta', 'reasoningContent')
  append_delta(index, delta) if delta
end

#raw_reasoningObject



25
26
27
28
29
# File 'lib/ruby_llm/protocols/converse/thinking_stream.rb', line 25

def raw_reasoning
  return if @blocks.empty?

  { 'converse' => @blocks.sort.map { |_index, content| { 'reasoningContent' => content } } }
end