Class: Geminize::Models::FunctionResponse
- Inherits:
-
Object
- Object
- Geminize::Models::FunctionResponse
- Defined in:
- lib/geminize/models/function_response.rb
Overview
Represents a function response from Gemini API
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the function that was called.
-
#response ⇒ Hash, ...
readonly
The response from the function.
Class Method Summary collapse
-
.from_hash(hash) ⇒ Geminize::Models::FunctionResponse
Create a FunctionResponse from a hash.
Instance Method Summary collapse
-
#initialize(name, response) ⇒ FunctionResponse
constructor
Initialize a new function response.
-
#to_h ⇒ Hash
Alias for to_hash.
-
#to_hash ⇒ Hash
Convert the function response to a hash.
-
#validate! ⇒ Boolean
Validate the function response.
Constructor Details
#initialize(name, response) ⇒ FunctionResponse
Initialize a new function response
16 17 18 19 20 |
# File 'lib/geminize/models/function_response.rb', line 16 def initialize(name, response) @name = name @response = response validate! end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns The name of the function that was called.
8 9 10 |
# File 'lib/geminize/models/function_response.rb', line 8 def name @name end |
#response ⇒ Hash, ... (readonly)
Returns The response from the function.
11 12 13 |
# File 'lib/geminize/models/function_response.rb', line 11 def response @response end |
Class Method Details
.from_hash(hash) ⇒ Geminize::Models::FunctionResponse
Create a FunctionResponse from a hash
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/geminize/models/function_response.rb', line 40 def self.from_hash(hash) unless hash.is_a?(Hash) raise Geminize::ValidationError.new( "Expected a Hash, got #{hash.class}", "INVALID_ARGUMENT" ) end name = hash["name"] || hash[:name] response = hash["response"] || hash[:response] new(name, response) end |
Instance Method Details
#to_h ⇒ Hash
Alias for to_hash
65 66 67 |
# File 'lib/geminize/models/function_response.rb', line 65 def to_h to_hash end |
#to_hash ⇒ Hash
Convert the function response to a hash
56 57 58 59 60 61 |
# File 'lib/geminize/models/function_response.rb', line 56 def to_hash { name: @name, response: @response } end |
#validate! ⇒ Boolean
Validate the function response
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/geminize/models/function_response.rb', line 25 def validate! if @name.nil? || @name.empty? raise Geminize::ValidationError.new( "Function name cannot be empty", "INVALID_ARGUMENT" ) end true end |