Class: RubyLLM::Protocols::Converse::ThinkingStream
- Inherits:
-
Object
- Object
- RubyLLM::Protocols::Converse::ThinkingStream
- Defined in:
- lib/ruby_llm/protocols/converse/thinking_stream.rb
Overview
:nodoc: all
Instance Method Summary collapse
- #add(event) ⇒ Object
-
#initialize ⇒ ThinkingStream
constructor
A new instance of ThinkingStream.
- #raw_reasoning ⇒ Object
Constructor Details
#initialize ⇒ ThinkingStream
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_reasoning ⇒ Object
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 |