Class: Helicone::ToolCall
- Inherits:
-
Object
- Object
- Helicone::ToolCall
- Defined in:
- lib/helicone/tool_call.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
-
.from_response(response) ⇒ Array<Helicone::ToolCall>
Parse tool calls from an API response (expects symbolized keys).
-
.result(tool_call_id:, content:) ⇒ Helicone::Message
Build a tool result message to send back to the API.
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Access arguments like a hash (supports both string and symbol keys).
-
#dig(*keys) ⇒ Object?
Dig into nested data in arguments.
-
#initialize(id:, name:, arguments:) ⇒ ToolCall
constructor
Initialize a tool call.
-
#to_h ⇒ Hash
Convert to hash for inspection.
Constructor Details
#initialize(id:, name:, arguments:) ⇒ ToolCall
Initialize a tool call
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/helicone/tool_call.rb', line 12 def initialize(id:, name:, arguments:) @id = id @name = name @arguments = if arguments.nil? {} elsif arguments.is_a?(String) deep_symbolize_keys(JSON.parse(arguments)) else deep_symbolize_keys(arguments) end end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
5 6 7 |
# File 'lib/helicone/tool_call.rb', line 5 def arguments @arguments end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/helicone/tool_call.rb', line 5 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/helicone/tool_call.rb', line 5 def name @name end |
Class Method Details
.from_response(response) ⇒ Array<Helicone::ToolCall>
Parse tool calls from an API response (expects symbolized keys)
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/helicone/tool_call.rb', line 28 def self.from_response(response) tool_calls = response.is_a?(Response) ? response.tool_calls : response return [] if tool_calls.nil? tool_calls.map do |tc| new( id: tc[:id], name: tc.dig(:function, :name), arguments: tc.dig(:function, :arguments) ) end end |
.result(tool_call_id:, content:) ⇒ Helicone::Message
Build a tool result message to send back to the API
46 47 48 |
# File 'lib/helicone/tool_call.rb', line 46 def self.result(tool_call_id:, content:) Message.tool_result(tool_call_id: tool_call_id, content: content) end |
Instance Method Details
#[](key) ⇒ Object?
Access arguments like a hash (supports both string and symbol keys)
65 66 67 |
# File 'lib/helicone/tool_call.rb', line 65 def [](key) arguments[key.to_sym] end |
#dig(*keys) ⇒ Object?
Dig into nested data in arguments
73 74 75 |
# File 'lib/helicone/tool_call.rb', line 73 def dig(*keys) arguments.dig(*keys.map(&:to_sym)) end |
#to_h ⇒ Hash
Convert to hash for inspection
53 54 55 56 57 58 59 |
# File 'lib/helicone/tool_call.rb', line 53 def to_h { id: id, name: name, arguments: arguments } end |