class RubyLLM::RequestShape::Part
A Part describes one piece of a turn by its kind and size, never by its content.
part.kind # => :tool_call part.name # => "find_tasks" part.size # => 42 part.unit # => :chars part.signed? # => true part.to_s # => "call find_tasks (args 42 chars), signed"
Attributes
The kind of piece: :text, :thinking, :image, :audio, :video, :document, :tool_call, :tool_result, or :other for a piece RubyLLM does not classify, such as a provider tool step.
The MIME type of media, as the request gives it or as its format implies, or nil.
The tool’s name for a tool call, and for a tool result the name of the call it answers, which is nil when no call in the request matches it. For an :other piece, the provider’s name for it.
The size of the piece as the request sends it, in unit: the characters of text, thinking, tool call arguments, and a tool result’s text, or of its JSON when it is structured data, and the bytes of inline media. Media inside a tool result follows it as parts of its own. Returns nil when there is nothing to measure, such as media sent by URL or thinking the provider encrypted.
Where media comes from: :inline for bytes in the request, :url for a link the provider fetches, or :file for a file stored with the provider. Returns nil for pieces that are not media.
Public Class Methods
# File lib/ruby_llm/request_shape/part.rb, line 54 def initialize(kind:, size: nil, unit: nil, name: nil, source: nil, mime_type: nil, signed: false) @kind = kind @size = size @unit = size && (unit || :chars) @name = name @source = source @mime_type = mime_type @signed = signed end
Creates a part. Every attribute but kind is optional. A size counts characters unless unit says :bytes; pass +signed: true+ when the piece carries a thinking signature.
Public Instance Methods
Source
# File lib/ruby_llm/request_shape/part.rb, line 66 def signed? @signed end
Returns whether the piece carries a thinking signature, the token a provider issues to verify replayed thinking or tool calls.
Source
# File lib/ruby_llm/request_shape/part.rb, line 84 def to_h hash = { kind: kind, name: name } hash[unit] = size if size hash.merge(source: source, mime_type: mime_type, signed: signed? || nil).compact end
Returns the part as a Hash, with its size under its unit, omitting attributes it does not have.
Source
# File lib/ruby_llm/request_shape/part.rb, line 78 def to_s signed? ? "#{description}, signed" : description end
Returns the part in words, with its size and unit:
text (13 chars) image/png (34512 bytes) document (url) result find_tasks (6859 chars) thinking (no text), signed