Class: Riffer::Messages::Tool

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

Instance Attribute Summary collapse

Attributes inherited from Base

#content

Instance Method Summary collapse

Constructor Details

#initialize(content, tool_call_id:, name:, error: nil, error_type: nil) ⇒ Tool

Returns a new instance of Tool.



6
7
8
9
10
11
12
# File 'lib/riffer/messages/tool.rb', line 6

def initialize(content, tool_call_id:, name:, error: nil, error_type: nil)
  super(content)
  @tool_call_id = tool_call_id
  @name = name
  @error = error
  @error_type = error_type
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



4
5
6
# File 'lib/riffer/messages/tool.rb', line 4

def error
  @error
end

#error_typeObject (readonly)

Returns the value of attribute error_type.



4
5
6
# File 'lib/riffer/messages/tool.rb', line 4

def error_type
  @error_type
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/riffer/messages/tool.rb', line 4

def name
  @name
end

#tool_call_idObject (readonly)

Returns the value of attribute tool_call_id.



4
5
6
# File 'lib/riffer/messages/tool.rb', line 4

def tool_call_id
  @tool_call_id
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/riffer/messages/tool.rb', line 14

def error?
  !@error.nil?
end

#roleObject



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

def role
  "tool"
end

#to_hObject



22
23
24
25
26
27
28
29
# File 'lib/riffer/messages/tool.rb', line 22

def to_h
  hash = {role: role, content: content, tool_call_id: tool_call_id, name: name}
  if error?
    hash[:error] = error
    hash[:error_type] = error_type
  end
  hash
end