Class: RubyLLM::Thinking

Inherits:
Object
  • Object
show all
Includes:
Support::Inspectable
Defined in:
lib/ruby_llm/thinking.rb,
lib/ruby_llm/thinking.rb

Overview

A Thinking holds the reasoning output a provider returned alongside a response. Instances appear on Message#thinking, and on Chunk#thinking while streaming, when the model exposes its thinking.

chat = RubyLLM.chat(model: 'claude-opus-5').with_thinking(display: :summarized)
response = chat.ask "What is 15 * 23?"
response.thinking&.text
response.thinking&.signature

Defined Under Namespace

Classes: Config, Controls

Constant Summary

Constants included from Support::Inspectable

Support::Inspectable::TRUNCATE_AT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Support::Inspectable

#full_inspect, #inspect, #pretty_print

Constructor Details

#initialize(text: nil, signature: nil) ⇒ Thinking

:nodoc:



23
24
25
26
# File 'lib/ruby_llm/thinking.rb', line 23

def initialize(text: nil, signature: nil) # :nodoc:
  @text = text
  @signature = signature
end

Instance Attribute Details

#signatureObject (readonly)

The provider's opaque signature or encrypted reasoning payload for the thinking block, or nil. Shown as redacted in pretty-print output.



21
22
23
# File 'lib/ruby_llm/thinking.rb', line 21

def signature
  @signature
end

#textObject (readonly)

The reasoning text the provider returned, or nil.



17
18
19
# File 'lib/ruby_llm/thinking.rb', line 17

def text
  @text
end

Class Method Details

.build(text: nil, signature: nil) ⇒ Object

:nodoc:



28
29
30
31
32
33
34
35
# File 'lib/ruby_llm/thinking.rb', line 28

def self.build(text: nil, signature: nil) # :nodoc:
  signature = nil if signature.is_a?(String) && signature.empty?
  text = nil if text.is_a?(String) && text.empty? && signature.nil?

  return nil if text.nil? && signature.nil?

  new(text: text, signature: signature)
end

Instance Method Details

#inspect_attributesObject

:nodoc:



37
38
39
# File 'lib/ruby_llm/thinking.rb', line 37

def inspect_attributes # :nodoc:
  { text: text, signature: signature ? '[REDACTED]' : nil }
end