Class: Geminize::Models::Tool
- Inherits:
-
Object
- Object
- Geminize::Models::Tool
- Defined in:
- lib/geminize/models/tool.rb
Overview
Represents a tool for function calling or code execution in Gemini API
Instance Attribute Summary collapse
-
#code_execution ⇒ Boolean
readonly
Whether this tool is a code execution tool.
-
#function_declaration ⇒ Geminize::Models::FunctionDeclaration?
readonly
The function declaration for this tool.
Instance Method Summary collapse
-
#initialize(function_declaration = nil, code_execution = false) ⇒ Tool
constructor
Initialize a new tool.
-
#to_h ⇒ Hash
Alias for to_hash.
-
#to_hash ⇒ Hash
Convert the tool to a hash for API requests.
-
#validate! ⇒ Boolean
Validate the tool.
Constructor Details
#initialize(function_declaration = nil, code_execution = false) ⇒ Tool
Initialize a new tool
17 18 19 20 21 |
# File 'lib/geminize/models/tool.rb', line 17 def initialize(function_declaration = nil, code_execution = false) @function_declaration = function_declaration @code_execution = code_execution validate! end |
Instance Attribute Details
#code_execution ⇒ Boolean (readonly)
Returns Whether this tool is a code execution tool.
11 12 13 |
# File 'lib/geminize/models/tool.rb', line 11 def code_execution @code_execution end |
#function_declaration ⇒ Geminize::Models::FunctionDeclaration? (readonly)
Returns The function declaration for this tool.
8 9 10 |
# File 'lib/geminize/models/tool.rb', line 8 def function_declaration @function_declaration end |
Instance Method Details
#to_h ⇒ Hash
Alias for to_hash
60 61 62 |
# File 'lib/geminize/models/tool.rb', line 60 def to_h to_hash end |
#to_hash ⇒ Hash
Convert the tool to a hash for API requests
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/geminize/models/tool.rb', line 46 def to_hash if @code_execution { code_execution: {} } else { functionDeclarations: @function_declaration.to_hash } end end |
#validate! ⇒ Boolean
Validate the tool
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/geminize/models/tool.rb', line 26 def validate! if !@code_execution && @function_declaration.nil? raise Geminize::ValidationError.new( "Either function_declaration or code_execution must be provided", "INVALID_ARGUMENT" ) end if @function_declaration && !@function_declaration.is_a?(Geminize::Models::FunctionDeclaration) raise Geminize::ValidationError.new( "Function declaration must be a FunctionDeclaration, got #{@function_declaration.class}", "INVALID_ARGUMENT" ) end true end |