class RubyLLM::RequestShape::Turn
A Turn describes one entry of a request’s conversation: a message, or one item where the provider sends a model’s reasoning and tool calls as items of their own.
turn = error.request_shape.turns.last turn.index # => 4 turn.role # => "user" turn.to_s # => "#4 user: text (31 chars)"
Attributes
The turn’s 0-indexed position in the request, the position a provider’s error message counts from.
The turn’s role as the payload names it, such as "model", or for an entry that names no role, its type, such as "function_call". Returns nil when the entry names neither.
Public Class Methods
# File lib/ruby_llm/request_shape/turn.rb, line 30 def initialize(index:, role:, parts: []) @index = index @role = role @parts = parts end
Creates a turn at index with role and parts.
Public Instance Methods
Source
# File lib/ruby_llm/request_shape/turn.rb, line 45 def to_h { index: index, role: role, parts: parts.map(&:to_h) } end
Returns the turn as a Hash with its index, role, and parts.
Source
# File lib/ruby_llm/request_shape/turn.rb, line 40 def to_s "##{[index, role].compact.join(' ')}: #{parts.empty? ? 'no parts' : parts.join(', ')}" end
Returns the turn as one line: its index, its role, and its parts.
turn.to_s # => "#3 model: thinking (11 chars), text (13 chars), signed"