Class: Riffer::Messages::Tool
Overview
Represents a tool execution result in a conversation.
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
The error message if the tool execution failed.
-
#error_type ⇒ Object
readonly
The type of error (:unknown_tool, :validation_error, :execution_error, :timeout_error).
-
#name ⇒ Object
readonly
The name of the tool that was called.
-
#tool_call_id ⇒ Object
readonly
The ID of the tool call this result responds to.
Attributes inherited from Base
Instance Method Summary collapse
-
#error? ⇒ Boolean
Returns true if the tool execution resulted in an error.
-
#initialize(content, tool_call_id:, name:, id: nil, error: nil, error_type: nil) ⇒ Tool
constructor
– : (String, tool_call_id: String, name: String, ?id: String?, ?error: String?, ?error_type: Symbol?) -> void.
-
#role ⇒ Object
– : () -> Symbol.
-
#to_h ⇒ Object
Converts the message to a hash.
Methods inherited from Base
#+, from_hash, #has_tool_calls?
Constructor Details
#initialize(content, tool_call_id:, name:, id: nil, error: nil, error_type: nil) ⇒ Tool
– : (String, tool_call_id: String, name: String, ?id: String?, ?error: String?, ?error_type: Symbol?) -> void
20 21 22 23 24 25 26 |
# File 'lib/riffer/messages/tool.rb', line 20 def initialize(content, tool_call_id:, name:, id: nil, error: nil, error_type: nil) super(content, id: id) @tool_call_id = tool_call_id @name = name @error = error @error_type = error_type end |
Instance Attribute Details
#error ⇒ Object (readonly)
The error message if the tool execution failed.
13 14 15 |
# File 'lib/riffer/messages/tool.rb', line 13 def error @error end |
#error_type ⇒ Object (readonly)
The type of error (:unknown_tool, :validation_error, :execution_error, :timeout_error).
16 17 18 |
# File 'lib/riffer/messages/tool.rb', line 16 def error_type @error_type end |
#name ⇒ Object (readonly)
The name of the tool that was called.
10 11 12 |
# File 'lib/riffer/messages/tool.rb', line 10 def name @name end |
#tool_call_id ⇒ Object (readonly)
The ID of the tool call this result responds to.
7 8 9 |
# File 'lib/riffer/messages/tool.rb', line 7 def tool_call_id @tool_call_id end |
Instance Method Details
#error? ⇒ Boolean
Returns true if the tool execution resulted in an error.
– : () -> bool
32 33 34 |
# File 'lib/riffer/messages/tool.rb', line 32 def error? !@error.nil? end |
#role ⇒ Object
– : () -> Symbol
38 39 40 |
# File 'lib/riffer/messages/tool.rb', line 38 def role :tool end |
#to_h ⇒ Object
Converts the message to a hash.
– : () -> Hash[Symbol, untyped]
46 47 48 49 50 51 52 53 54 |
# File 'lib/riffer/messages/tool.rb', line 46 def to_h hash = {role: role, content: content, tool_call_id: tool_call_id, name: name} #: Hash[Symbol, untyped] hash[:id] = id unless id.nil? if error? hash[:error] = error hash[:error_type] = error_type end hash end |