Class: Kreator::ToolResult
- Inherits:
-
Object
- Object
- Kreator::ToolResult
- Defined in:
- lib/kreator/tool_result.rb
Constant Summary collapse
- STATUSES =
%w[ok error].freeze
- INITIALIZE_OPTIONS =
%i[status metadata error].freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#tool_call_id ⇒ Object
readonly
Returns the value of attribute tool_call_id.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(tool_call_id:, name:, content:, **options) ⇒ ToolResult
constructor
A new instance of ToolResult.
- #to_h ⇒ Object
- #to_message ⇒ Object
Constructor Details
#initialize(tool_call_id:, name:, content:, **options) ⇒ ToolResult
Returns a new instance of ToolResult.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kreator/tool_result.rb', line 10 def initialize(tool_call_id:, name:, content:, **) () status = .fetch(:status, "ok") status = status.to_s raise ArgumentError, "unknown status: #{status.inspect}" unless STATUSES.include?(status) @tool_call_id = tool_call_id.to_s @name = name.to_s @content = content.to_s @status = status @metadata = .fetch(:metadata, {}) || {} @error = .fetch(:error, nil) end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
8 9 10 |
# File 'lib/kreator/tool_result.rb', line 8 def content @content end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
8 9 10 |
# File 'lib/kreator/tool_result.rb', line 8 def error @error end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
8 9 10 |
# File 'lib/kreator/tool_result.rb', line 8 def @metadata end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/kreator/tool_result.rb', line 8 def name @name end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/kreator/tool_result.rb', line 8 def status @status end |
#tool_call_id ⇒ Object (readonly)
Returns the value of attribute tool_call_id.
8 9 10 |
# File 'lib/kreator/tool_result.rb', line 8 def tool_call_id @tool_call_id end |
Class Method Details
.from_h(hash) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/kreator/tool_result.rb', line 24 def self.from_h(hash) new( tool_call_id: hash.fetch("tool_call_id", hash[:tool_call_id]), name: hash.fetch("name", hash[:name]), content: hash.fetch("content", hash[:content] || ""), status: hash.fetch("status", hash[:status] || "ok"), metadata: hash.fetch("metadata", hash[:metadata] || {}), error: hash.fetch("error", hash[:error] || nil) ) end |
Instance Method Details
#to_h ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/kreator/tool_result.rb', line 39 def to_h { "tool_call_id" => tool_call_id, "name" => name, "content" => content, "status" => status, "metadata" => , "error" => error }.compact end |