Class: Legion::LLM::Types::ContentBlock

Inherits:
Data
  • Object
show all
Defined in:
lib/legion/llm/types/content_block.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cache_controlObject (readonly)

Returns the value of attribute cache_control

Returns:

  • (Object)

    the current value of cache_control



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def cache_control
  @cache_control
end

#codeObject (readonly)

Returns the value of attribute code

Returns:

  • (Object)

    the current value of code



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def code
  @code
end

#dataObject (readonly)

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def data
  @data
end

#detailObject (readonly)

Returns the value of attribute detail

Returns:

  • (Object)

    the current value of detail



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def detail
  @detail
end

#end_indexObject (readonly)

Returns the value of attribute end_index

Returns:

  • (Object)

    the current value of end_index



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def end_index
  @end_index
end

#file_idObject (readonly)

Returns the value of attribute file_id

Returns:

  • (Object)

    the current value of file_id



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def file_id
  @file_id
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def id
  @id
end

#inputObject (readonly)

Returns the value of attribute input

Returns:

  • (Object)

    the current value of input



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def input
  @input
end

#is_errorObject (readonly)

Returns the value of attribute is_error

Returns:

  • (Object)

    the current value of is_error



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def is_error
  @is_error
end

#media_typeObject (readonly)

Returns the value of attribute media_type

Returns:

  • (Object)

    the current value of media_type



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def media_type
  @media_type
end

#messageObject (readonly)

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def message
  @message
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def name
  @name
end

#sourceObject (readonly)

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def source
  @source
end

#source_typeObject (readonly)

Returns the value of attribute source_type

Returns:

  • (Object)

    the current value of source_type



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def source_type
  @source_type
end

#start_indexObject (readonly)

Returns the value of attribute start_index

Returns:

  • (Object)

    the current value of start_index



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def start_index
  @start_index
end

#textObject (readonly)

Returns the value of attribute text

Returns:

  • (Object)

    the current value of text



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def text
  @text
end

#tool_use_idObject (readonly)

Returns the value of attribute tool_use_id

Returns:

  • (Object)

    the current value of tool_use_id



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def tool_use_id
  @tool_use_id
end

#typeObject (readonly)

Returns the value of attribute type

Returns:

  • (Object)

    the current value of type



6
7
8
# File 'lib/legion/llm/types/content_block.rb', line 6

def type
  @type
end

Class Method Details

.build_with(**overrides) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/legion/llm/types/content_block.rb', line 39

def self.build_with(**overrides)
  defaults = {
    type: nil, text: nil, 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
  }
  new(**defaults, **overrides)
end

.from_hash(hash) ⇒ Object



34
35
36
37
# File 'lib/legion/llm/types/content_block.rb', line 34

def self.from_hash(hash)
  hash = hash.transform_keys(&:to_sym) if hash.respond_to?(:transform_keys)
  build_with(**hash)
end

.image(data:, media_type:, source_type: :base64, detail: nil) ⇒ Object



29
30
31
32
# File 'lib/legion/llm/types/content_block.rb', line 29

def self.image(data:, media_type:, source_type: :base64, detail: nil)
  build_with(type: :image, data: data, media_type: media_type,
             source_type: source_type, detail: detail)
end

.text(content, cache_control: nil) ⇒ Object



13
14
15
# File 'lib/legion/llm/types/content_block.rb', line 13

def self.text(content, cache_control: nil)
  build_with(type: :text, text: content, cache_control: cache_control)
end

.thinking(content) ⇒ Object



17
18
19
# File 'lib/legion/llm/types/content_block.rb', line 17

def self.thinking(content)
  build_with(type: :thinking, text: content)
end

.tool_result(tool_use_id:, content:, is_error: false) ⇒ Object



25
26
27
# File 'lib/legion/llm/types/content_block.rb', line 25

def self.tool_result(tool_use_id:, content:, is_error: false)
  build_with(type: :tool_result, tool_use_id: tool_use_id, text: content, is_error: is_error)
end

.tool_use(id:, name:, input:) ⇒ Object



21
22
23
# File 'lib/legion/llm/types/content_block.rb', line 21

def self.tool_use(id:, name:, input:)
  build_with(type: :tool_use, id: id, name: name, input: input)
end

Instance Method Details

#to_hObject



49
50
51
# File 'lib/legion/llm/types/content_block.rb', line 49

def to_h
  super.compact
end