Class: Legion::Extensions::Llm::Canonical::ContentBlock
- Inherits:
-
Data
- Object
- Data
- Legion::Extensions::Llm::Canonical::ContentBlock
- Defined in:
- lib/legion/extensions/llm/canonical/content_block.rb
Overview
Typed content block with media_type support per G20a. Ports field vocabulary from Legion::LLM::Types::ContentBlock.
Constant Summary collapse
- CONTENT_BLOCK_TYPES =
%i[text thinking tool_use tool_result image audio video].freeze
Instance Attribute Summary collapse
-
#cache_control ⇒ Object
readonly
Returns the value of attribute cache_control.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#detail ⇒ Object
readonly
Returns the value of attribute detail.
-
#end_index ⇒ Object
readonly
Returns the value of attribute end_index.
-
#file_id ⇒ Object
readonly
Returns the value of attribute file_id.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#is_error ⇒ Object
readonly
Returns the value of attribute is_error.
-
#media_type ⇒ Object
readonly
Returns the value of attribute media_type.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#source_type ⇒ Object
readonly
Returns the value of attribute source_type.
-
#start_index ⇒ Object
readonly
Returns the value of attribute start_index.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
-
#tool_use_id ⇒ Object
readonly
Returns the value of attribute tool_use_id.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.from_hash(source) ⇒ Object
Build from a Hash (raw provider response or deserialized wire payload).
-
.image(data:, media_type:, source_type: :base64, detail: nil) ⇒ Object
Build an image content block with media_type (G20a).
-
.text(content, cache_control: nil) ⇒ Object
Build a text content block.
-
.thinking(content) ⇒ Object
Build a thinking content block.
-
.tool_result(tool_use_id:, content:, is_error: false) ⇒ Object
Build a tool_result content block.
-
.tool_use(id:, name:, input:) ⇒ Object
Build a tool_use content block.
Instance Method Summary collapse
-
#text? ⇒ Boolean
Whether this block carries textual content.
-
#thinking? ⇒ Boolean
Whether this block carries thinking/reasoning content.
-
#to_h ⇒ Object
Serialize to a Hash for AMQP/fleet/wire transport.
-
#tool_result? ⇒ Boolean
Whether this block represents a tool result.
-
#tool_use? ⇒ Boolean
Whether this block represents a tool use request.
Instance Attribute Details
#cache_control ⇒ Object (readonly)
Returns the value of attribute cache_control
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def cache_control @cache_control end |
#code ⇒ Object (readonly)
Returns the value of attribute code
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def code @code end |
#data ⇒ Object (readonly)
Returns the value of attribute data
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def data @data end |
#detail ⇒ Object (readonly)
Returns the value of attribute detail
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def detail @detail end |
#end_index ⇒ Object (readonly)
Returns the value of attribute end_index
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def end_index @end_index end |
#file_id ⇒ Object (readonly)
Returns the value of attribute file_id
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def file_id @file_id end |
#id ⇒ Object (readonly)
Returns the value of attribute id
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def id @id end |
#input ⇒ Object (readonly)
Returns the value of attribute input
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def input @input end |
#is_error ⇒ Object (readonly)
Returns the value of attribute is_error
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def is_error @is_error end |
#media_type ⇒ Object (readonly)
Returns the value of attribute media_type
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def media_type @media_type end |
#message ⇒ Object (readonly)
Returns the value of attribute message
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def @message end |
#name ⇒ Object (readonly)
Returns the value of attribute name
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def name @name end |
#source ⇒ Object (readonly)
Returns the value of attribute source
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def source @source end |
#source_type ⇒ Object (readonly)
Returns the value of attribute source_type
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def source_type @source_type end |
#start_index ⇒ Object (readonly)
Returns the value of attribute start_index
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def start_index @start_index end |
#text ⇒ Object (readonly)
Returns the value of attribute text
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def text @text end |
#tool_use_id ⇒ Object (readonly)
Returns the value of attribute tool_use_id
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def tool_use_id @tool_use_id end |
#type ⇒ Object (readonly)
Returns the value of attribute type
9 10 11 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 9 def type @type end |
Class Method Details
.from_hash(source) ⇒ Object
Build from a Hash (raw provider response or deserialized wire payload).
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 67 def self.from_hash(source) return nil if source.nil? h = source.transform_keys(&:to_sym) type_raw = h.delete(:type) h[:type] = type_raw&.to_sym if type_raw new( type: h[:type], text: h[:text], data: h[:data], source_type: h[:source_type], media_type: h[:media_type], detail: h[:detail], name: h[:name], file_id: h[:file_id], id: h[:id], input: h[:input], tool_use_id: h[:tool_use_id], is_error: h[:is_error], source: h[:source], start_index: h[:start_index], end_index: h[:end_index], code: h[:code], message: h[:message], cache_control: h[:cache_control] ) end |
.image(data:, media_type:, source_type: :base64, detail: nil) ⇒ Object
Build an image content block with media_type (G20a).
57 58 59 60 61 62 63 64 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 57 def self.image(data:, media_type:, source_type: :base64, detail: nil) new( type: :image, text: nil, data: data, source_type: source_type, media_type: media_type, detail: detail, name: nil, file_id: nil, id: nil, input: nil, tool_use_id: nil, is_error: nil, source: nil, start_index: nil, end_index: nil, code: nil, message: nil, cache_control: nil ) end |
.text(content, cache_control: nil) ⇒ Object
Build a text content block.
17 18 19 20 21 22 23 24 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 17 def self.text(content, cache_control: nil) new( type: :text, text: content, data: nil, source_type: nil, media_type: nil, detail: nil, name: nil, file_id: nil, id: nil, input: nil, tool_use_id: nil, is_error: nil, source: nil, start_index: nil, end_index: nil, code: nil, message: nil, cache_control: cache_control ) end |
.thinking(content) ⇒ Object
Build a thinking content block.
27 28 29 30 31 32 33 34 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 27 def self.thinking(content) new( type: :thinking, text: content, data: nil, source_type: nil, media_type: nil, detail: nil, name: nil, file_id: nil, id: nil, input: nil, tool_use_id: nil, is_error: nil, source: nil, start_index: nil, end_index: nil, code: nil, message: nil, cache_control: nil ) end |
.tool_result(tool_use_id:, content:, is_error: false) ⇒ Object
Build a tool_result content block.
47 48 49 50 51 52 53 54 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 47 def self.tool_result(tool_use_id:, content:, is_error: false) new( type: :tool_result, text: content, data: nil, source_type: nil, media_type: nil, detail: nil, name: nil, file_id: nil, id: nil, input: nil, tool_use_id: tool_use_id, is_error: is_error, source: nil, start_index: nil, end_index: nil, code: nil, message: nil, cache_control: nil ) end |
.tool_use(id:, name:, input:) ⇒ Object
Build a tool_use content block.
37 38 39 40 41 42 43 44 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 37 def self.tool_use(id:, name:, input:) new( type: :tool_use, text: nil, data: nil, source_type: nil, media_type: nil, detail: nil, name: name, file_id: nil, id: id, input: input, tool_use_id: nil, is_error: nil, source: nil, start_index: nil, end_index: nil, code: nil, message: nil, cache_control: nil ) end |
Instance Method Details
#text? ⇒ Boolean
Whether this block carries textual content.
102 103 104 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 102 def text? type == :text end |
#thinking? ⇒ Boolean
Whether this block carries thinking/reasoning content.
107 108 109 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 107 def thinking? type == :thinking end |
#to_h ⇒ Object
Serialize to a Hash for AMQP/fleet/wire transport.
97 98 99 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 97 def to_h super.compact end |
#tool_result? ⇒ Boolean
Whether this block represents a tool result.
117 118 119 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 117 def tool_result? type == :tool_result end |
#tool_use? ⇒ Boolean
Whether this block represents a tool use request.
112 113 114 |
# File 'lib/legion/extensions/llm/canonical/content_block.rb', line 112 def tool_use? type == :tool_use end |