Class: Geminize::Models::Model

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

Overview

Represents an AI model from the Gemini API.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Model

Create a new Model instance

Parameters:

  • attributes (Hash) (defaults to: {})

    Model attributes

Options Hash (attributes):

  • :name (String)

    The resource name of the model

  • :base_model_id (String)

    The base model ID

  • :version (String)

    The model version

  • :display_name (String)

    The display name of the model

  • :description (String)

    The model description

  • :input_token_limit (Integer)

    Maximum input tokens

  • :output_token_limit (Integer)

    Maximum output tokens

  • :supported_generation_methods (Array<String>)

    Supported methods

  • :temperature (Float)

    Default temperature

  • :max_temperature (Float)

    Maximum temperature

  • :top_p (Float)

    Default top_p value

  • :top_k (Integer)

    Default top_k value

  • :raw_data (Hash)

    Raw model data from API



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/geminize/models/model.rb', line 61

def initialize(attributes = {})
  @name = attributes[:name]
  @base_model_id = attributes[:base_model_id]
  @version = attributes[:version]
  @display_name = attributes[:display_name]
  @description = attributes[:description]
  @input_token_limit = attributes[:input_token_limit]
  @output_token_limit = attributes[:output_token_limit]
  @supported_generation_methods = attributes[:supported_generation_methods] || []
  @temperature = attributes[:temperature]
  @max_temperature = attributes[:max_temperature]
  @top_p = attributes[:top_p]
  @top_k = attributes[:top_k]
  @raw_data = attributes[:raw_data] || {}
end

Instance Attribute Details

#base_model_idString (readonly)

Returns The base model ID.

Returns:

  • (String)

    The base model ID



11
12
13
# File 'lib/geminize/models/model.rb', line 11

def base_model_id
  @base_model_id
end

#descriptionString (readonly)

Returns The model description.

Returns:

  • (String)

    The model description



20
21
22
# File 'lib/geminize/models/model.rb', line 20

def description
  @description
end

#display_nameString (readonly)

Returns The display name of the model.

Returns:

  • (String)

    The display name of the model



17
18
19
# File 'lib/geminize/models/model.rb', line 17

def display_name
  @display_name
end

#input_token_limitInteger (readonly)

Returns Maximum number of input tokens allowed.

Returns:

  • (Integer)

    Maximum number of input tokens allowed



23
24
25
# File 'lib/geminize/models/model.rb', line 23

def input_token_limit
  @input_token_limit
end

#max_temperatureFloat (readonly)

Returns Maximum allowed temperature.

Returns:

  • (Float)

    Maximum allowed temperature



35
36
37
# File 'lib/geminize/models/model.rb', line 35

def max_temperature
  @max_temperature
end

#nameString (readonly)

Returns The resource name of the model.

Returns:

  • (String)

    The resource name of the model



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

def name
  @name
end

#output_token_limitInteger (readonly)

Returns Maximum number of output tokens available.

Returns:

  • (Integer)

    Maximum number of output tokens available



26
27
28
# File 'lib/geminize/models/model.rb', line 26

def output_token_limit
  @output_token_limit
end

#raw_dataHash (readonly)

Returns Raw model data from the API.

Returns:

  • (Hash)

    Raw model data from the API



44
45
46
# File 'lib/geminize/models/model.rb', line 44

def raw_data
  @raw_data
end

#supported_generation_methodsArray<String> (readonly)

Returns Supported generation methods.

Returns:

  • (Array<String>)

    Supported generation methods



29
30
31
# File 'lib/geminize/models/model.rb', line 29

def supported_generation_methods
  @supported_generation_methods
end

#temperatureFloat (readonly)

Returns Default temperature.

Returns:

  • (Float)

    Default temperature



32
33
34
# File 'lib/geminize/models/model.rb', line 32

def temperature
  @temperature
end

#top_kInteger (readonly)

Returns Default top_k value for sampling.

Returns:

  • (Integer)

    Default top_k value for sampling



41
42
43
# File 'lib/geminize/models/model.rb', line 41

def top_k
  @top_k
end

#top_pFloat (readonly)

Returns Default top_p value for nucleus sampling.

Returns:

  • (Float)

    Default top_p value for nucleus sampling



38
39
40
# File 'lib/geminize/models/model.rb', line 38

def top_p
  @top_p
end

#versionString (readonly)

Returns The model version.

Returns:

  • (String)

    The model version



14
15
16
# File 'lib/geminize/models/model.rb', line 14

def version
  @version
end

Class Method Details

.from_api_data(data) ⇒ Model

Create a Model from API response data

Parameters:

  • data (Hash)

    Raw API response data

Returns:

  • (Model)

    New Model instance



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/geminize/models/model.rb', line 144

def self.from_api_data(data)
  new(
    name: data["name"],
    base_model_id: data["baseModelId"],
    version: data["version"],
    display_name: data["displayName"],
    description: data["description"],
    input_token_limit: data["inputTokenLimit"],
    output_token_limit: data["outputTokenLimit"],
    supported_generation_methods: data["supportedGenerationMethods"] || [],
    temperature: data["temperature"],
    max_temperature: data["maxTemperature"],
    top_p: data["topP"],
    top_k: data["topK"],
    raw_data: data
  )
end

Instance Method Details

#idString

Shorthand accessor for the model ID (last part of the name path)

Returns:

  • (String)

    The model ID



79
80
81
82
# File 'lib/geminize/models/model.rb', line 79

def id
  return nil unless @name
  @name.split("/").last
end

#supports_content_generation?Boolean

Check if model supports content generation

Returns:

  • (Boolean)

    True if the model supports content generation



93
94
95
# File 'lib/geminize/models/model.rb', line 93

def supports_content_generation?
  supports_method?("generateContent")
end

#supports_embedding?Boolean

Check if model supports embedding generation

Returns:

  • (Boolean)

    True if the model supports embedding generation



105
106
107
# File 'lib/geminize/models/model.rb', line 105

def supports_embedding?
  supports_method?("embedContent")
end

#supports_message_generation?Boolean

Check if model supports message generation (chat)

Returns:

  • (Boolean)

    True if the model supports message generation



99
100
101
# File 'lib/geminize/models/model.rb', line 99

def supports_message_generation?
  supports_method?("generateMessage")
end

#supports_method?(method) ⇒ Boolean

Check if model supports a specific generation method

Parameters:

  • method (String)

    Generation method to check for

Returns:

  • (Boolean)

    True if the model supports the method



87
88
89
# File 'lib/geminize/models/model.rb', line 87

def supports_method?(method)
  supported_generation_methods.include?(method.to_s)
end

#supports_streaming?Boolean

Check if model supports streaming content generation

Returns:

  • (Boolean)

    True if the model supports streaming content generation



111
112
113
# File 'lib/geminize/models/model.rb', line 111

def supports_streaming?
  supports_method?("streamGenerateContent")
end

#to_hHash

Convert model to a hash representation

Returns:

  • (Hash)

    Hash representation of the model



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/geminize/models/model.rb', line 117

def to_h
  {
    name: name,
    id: id,
    base_model_id: base_model_id,
    version: version,
    display_name: display_name,
    description: description,
    input_token_limit: input_token_limit,
    output_token_limit: output_token_limit,
    supported_generation_methods: supported_generation_methods,
    temperature: temperature,
    max_temperature: max_temperature,
    top_p: top_p,
    top_k: top_k
  }
end

#to_json(*args) ⇒ String

Convert model to JSON string

Returns:

  • (String)

    JSON representation of the model



137
138
139
# File 'lib/geminize/models/model.rb', line 137

def to_json(*args)
  to_h.to_json(*args)
end