Class: Kreator::ToolResult

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool_call_id:, name:, content:, **options) ⇒ ToolResult

Returns a new instance of ToolResult.

Raises:

  • (ArgumentError)


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:, **options)
  validate_initialize_options!(options)
  status = options.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 = options.fetch(:metadata, {}) || {}
  @error = options.fetch(:error, nil)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



8
9
10
# File 'lib/kreator/tool_result.rb', line 8

def content
  @content
end

#errorObject (readonly)

Returns the value of attribute error.



8
9
10
# File 'lib/kreator/tool_result.rb', line 8

def error
  @error
end

#metadataObject (readonly)

Returns the value of attribute metadata.



8
9
10
# File 'lib/kreator/tool_result.rb', line 8

def 
  @metadata
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/kreator/tool_result.rb', line 8

def name
  @name
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/kreator/tool_result.rb', line 8

def status
  @status
end

#tool_call_idObject (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_hObject



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

#to_messageObject



35
36
37
# File 'lib/kreator/tool_result.rb', line 35

def to_message
  Message.tool(content: content, tool_call_id: tool_call_id, name: name)
end