Class: Google::Genai::Models

Inherits:
Object
  • Object
show all
Defined in:
lib/google/genai/models.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_client) ⇒ Models

Returns a new instance of Models.



9
10
11
# File 'lib/google/genai/models.rb', line 9

def initialize(api_client)
  @api_client = api_client
end

Instance Method Details

#generate_content(model:, contents:, config: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/google/genai/models.rb', line 13

def generate_content(model:, contents:, config: nil)
  path = "v1beta/models/#{model}:generateContent"
  body = {
    contents: normalize_contents(contents)
  }
  body[:generationConfig] = config if config

  response = @api_client.request(:post, path, body: body)
  Types::GenerateContentResponse.new(JSON.parse(response.body))
end

#list(config: nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/google/genai/models.rb', line 24

def list(config: nil)
  query_base = config&.dig(:query_base) != false
  
  list_request = ->(options) do
    path = "v1beta/#{query_base ? 'models' : 'tunedModels'}"
    params = {}
    params[:pageToken] = options[:page_token] if options&.key?(:page_token)
    params[:pageSize] = options[:page_size] if options&.key?(:page_size)
    path += "?#{URI.encode_www_form(params)}" unless params.empty?
    @api_client.get(path)
  end

  response = list_request.call(config)

  Pager.new(
    name: query_base ? :models : :tunedModels,
    request: list_request,
    response: response,
    config: config,
    item_class: Types::Model
  )
end