Class: Legion::Extensions::Llm::Canonical::Thinking

Inherits:
Data
  • Object
show all
Defined in:
lib/legion/extensions/llm/canonical/thinking.rb

Overview

Canonical thinking/reasoning block. Ports field vocabulary from Legion::LLM::Types and lex-llm Thinking.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



11
12
13
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 11

def content
  @content
end

#signatureObject (readonly)

Returns the value of attribute signature

Returns:

  • (Object)

    the current value of signature



11
12
13
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 11

def signature
  @signature
end

Class Method Details

.from_hash(source) ⇒ Object

Build from a Hash (raw provider response or deserialized wire payload).



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 13

def self.from_hash(source)
  return nil if source.nil?

  h = source.transform_keys(&:to_sym)

  # Treat empty strings as nil
  content = h[:content]
  content = nil if content.is_a?(String) && content.empty?
  signature = h[:signature]
  signature = nil if signature.is_a?(String) && signature.empty?

  return nil if content.nil? && signature.nil?

  new(content: content, signature: signature)
end

Instance Method Details

#empty?Boolean

Whether this thinking block has any content.

Returns:

  • (Boolean)


35
36
37
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 35

def empty?
  content.nil? && signature.nil?
end

#to_hObject

Serialize to a Hash for AMQP/fleet/wire transport.



30
31
32
# File 'lib/legion/extensions/llm/canonical/thinking.rb', line 30

def to_h
  super.compact
end