Class: Riffer::Messages::Assistant

Inherits:
Base
  • Object
show all
Defined in:
lib/riffer/messages/assistant.rb

Overview

Represents an assistant (LLM) message in a conversation.

May include tool calls when the LLM requests tool execution.

msg = Riffer::Messages::Assistant.new("Hello!")
msg.role        # => :assistant
msg.content     # => "Hello!"
msg.tool_calls  # => []

Instance Attribute Summary collapse

Attributes inherited from Base

#content

Instance Method Summary collapse

Constructor Details

#initialize(content, tool_calls: []) ⇒ Assistant

Creates a new assistant message.

content

String - the message content

tool_calls

Array of Hash - optional tool calls



24
25
26
27
# File 'lib/riffer/messages/assistant.rb', line 24

def initialize(content, tool_calls: [])
  super(content)
  @tool_calls = tool_calls
end

Instance Attribute Details

#tool_callsObject (readonly)

Array of tool calls requested by the assistant.

Each tool call is a Hash with :id, :call_id, :name, and :arguments keys.

Returns Array of Hash.



18
19
20
# File 'lib/riffer/messages/assistant.rb', line 18

def tool_calls
  @tool_calls
end

Instance Method Details

#roleObject

Returns :assistant.



30
31
32
# File 'lib/riffer/messages/assistant.rb', line 30

def role
  :assistant
end

#to_hObject

Converts the message to a hash.

Returns Hash with :role, :content, and optionally :tool_calls.



37
38
39
40
41
# File 'lib/riffer/messages/assistant.rb', line 37

def to_h
  hash = {role: role, content: content}
  hash[:tool_calls] = tool_calls unless tool_calls.empty?
  hash
end