Class: Intelligence::MessageContent::ToolCall
- Inherits:
-
Base
- Object
- Base
- Intelligence::MessageContent::ToolCall
show all
- Defined in:
- lib/intelligence/message_content/tool_call.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Attribute Details
Returns the value of attribute tool_call_id.
12
13
14
|
# File 'lib/intelligence/message_content/tool_call.rb', line 12
def tool_call_id
@tool_call_id
end
|
Returns the value of attribute tool_name.
13
14
15
|
# File 'lib/intelligence/message_content/tool_call.rb', line 13
def tool_name
@tool_name
end
|
Instance Method Details
#merge(other_tool_call) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/intelligence/message_content/tool_call.rb', line 41
def merge( other_tool_call )
other_tool_call_id = other_tool_call.tool_call_id
other_tool_name = other_tool_call.tool_name
other_tool_parameters = other_tool_call.tool_parameters( repair: false, parse: false )
raise ArgumentError,
"The given tool call parameters are incompative with this tool's parameters." \
unless @tool_parameters.nil? || other_tool_parameters.nil? ||
@tool_parameters.is_a?( other_tool_parameters.class )
tool_call_id = other_tool_call_id.nil? ?
@tool_call_id : @tool_call_id || '' + other_tool_call_id
tool_name = other_tool_name.nil? ?
@tool_name : @tool_name || '' + other_tool_name
tool_parameters = @tool_parameters
unless other_tool_parameters.nil?
if other_tool_parameters.is_a?( Hash )
tool_parameters = ( tool_parameters || {} ).merge( other_tool_parameters )
else
tool_parameters = ( tool_parameters || '' ) + other_tool_parameters
end
end
self.class.new(
tool_call_id: tool_call_id,
tool_name: tool_name,
tool_parameters: tool_parameters
)
end
|
#to_h ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'lib/intelligence/message_content/tool_call.rb', line 72
def to_h
{
type: :tool_call,
tool_call_id: tool_call_id,
tool_name: tool_name,
tool_parameters: tool_parameters
}.compact
end
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/intelligence/message_content/tool_call.rb', line 15
def tool_parameters( options = nil )
return @tool_parameters if @tool_parameters.nil? || @tool_parameters.is_a?( Hash )
options = options || {}
parse = options.key?( :parse ) ? options[ :parse ] : true
return @parsed_tool_parameters if @parsed_tool_parameters && parse
tool_parameters = ( options.key?( :repair ) ? options[ :repair ] : true ) ?
JSON.repair( @tool_parameters ) : @tool_parameters
if parse
@parsed_tool_parameters = tool_parameters =
JSON.parse(
tool_parameters,
parse.is_a?( Hash ) ? parse : { symbolize_names: true }
)
end
tool_parameters
end
|
#valid? ⇒ Boolean
37
38
39
|
# File 'lib/intelligence/message_content/tool_call.rb', line 37
def valid?
tool_name && !tool_name.empty?
end
|