Class: Geminize::Models::FunctionResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/geminize/models/function_response.rb

Overview

Represents a function response from Gemini API

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, response) ⇒ FunctionResponse

Initialize a new function response

Parameters:

  • name (String)

    The name of the function that was called

  • response (Hash, Array, String, Numeric, Boolean, nil)

    The response from the function



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

#nameString (readonly)

Returns The name of the function that was called.

Returns:

  • (String)

    The name of the function that was called



8
9
10
# File 'lib/geminize/models/function_response.rb', line 8

def name
  @name
end

#responseHash, ... (readonly)

Returns The response from the function.

Returns:

  • (Hash, Array, String, Numeric, Boolean, nil)

    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

Parameters:

  • hash (Hash)

    The hash representation of a function response

Returns:

Raises:



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_hHash

Alias for to_hash

Returns:

  • (Hash)

    The function response as a hash



65
66
67
# File 'lib/geminize/models/function_response.rb', line 65

def to_h
  to_hash
end

#to_hashHash

Convert the function response to a hash

Returns:

  • (Hash)

    The function response as 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

Returns:

  • (Boolean)

    true if validation passes

Raises:



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