Class: PromptObjects::LLM::ToolCall

Inherits:
Object
  • Object
show all
Defined in:
lib/prompt_objects/llm/response.rb

Overview

Represents a single tool call from the LLM. Supports both method access (.id) and hash access ([:id]) for compatibility with code that may receive either ToolCall objects or Hashes from the DB.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, arguments:, provider_metadata: nil) ⇒ ToolCall

Returns a new instance of ToolCall.



30
31
32
33
34
35
# File 'lib/prompt_objects/llm/response.rb', line 30

def initialize(id:, name:, arguments:, provider_metadata: nil)
  @id = id
  @name = name
  @arguments = arguments
  @provider_metadata =  || {}
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



28
29
30
# File 'lib/prompt_objects/llm/response.rb', line 28

def arguments
  @arguments
end

#idObject (readonly)

Returns the value of attribute id.



28
29
30
# File 'lib/prompt_objects/llm/response.rb', line 28

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/prompt_objects/llm/response.rb', line 28

def name
  @name
end

#provider_metadataObject (readonly)

Returns the value of attribute provider_metadata.



28
29
30
# File 'lib/prompt_objects/llm/response.rb', line 28

def 
  @provider_metadata
end

Class Method Details

.from_hash(hash) ⇒ Object

Create a ToolCall from a Hash (for deserialization)



55
56
57
58
59
60
61
62
63
64
# File 'lib/prompt_objects/llm/response.rb', line 55

def self.from_hash(hash)
  return hash if hash.is_a?(ToolCall)

  new(
    id: hash[:id] || hash["id"],
    name: hash[:name] || hash["name"],
    arguments: hash[:arguments] || hash["arguments"] || {},
    provider_metadata: hash[:provider_metadata] || hash["provider_metadata"] || {}
  )
end

Instance Method Details

#[](key) ⇒ Object

Allow hash-style access for compatibility with code expecting Hashes



38
39
40
41
42
43
44
45
# File 'lib/prompt_objects/llm/response.rb', line 38

def [](key)
  case key.to_sym
  when :id then @id
  when :name then @name
  when :arguments then @arguments
  when :provider_metadata then @provider_metadata
  end
end

#to_hObject

Convert to a plain Hash (for serialization)



48
49
50
51
52
# File 'lib/prompt_objects/llm/response.rb', line 48

def to_h
  result = { id: @id, name: @name, arguments: @arguments }
  result[:provider_metadata] = @provider_metadata unless @provider_metadata.empty?
  result
end