Class: Google::Genai::Tunings

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

Instance Method Summary collapse

Constructor Details

#initialize(api_client) ⇒ Tunings



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

def initialize(api_client)
  @api_client = api_client
end

Instance Method Details

#cancel(name:, config: nil) ⇒ Object



57
58
59
60
61
# File 'lib/google/genai/tunings.rb', line 57

def cancel(name:, config: nil)
  raise "Tuning is only supported for Vertex AI" unless @api_client.vertexai
  @api_client.request(:post, "v1beta/#{name}:cancel", body: {})
  nil
end

#create(base_model:, training_dataset:, config: nil) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/google/genai/tunings.rb', line 13

def create(base_model:, training_dataset:, config: nil)
  raise "Tuning is only supported for Vertex AI" unless @api_client.vertexai

  body = {
    baseModel: base_model,
    supervisedTuningSpec: {
      trainingDatasetUri: training_dataset[:gcs_uri] || training_dataset[:vertex_dataset_resource]
    }
  }
  # TODO: Add other config options

  response = @api_client.request(:post, "v1beta/tuningJobs", body: body)
  Types::TuningJob.new(JSON.parse(response.body))
end

#get(name:, config: nil) ⇒ Object



28
29
30
31
32
# File 'lib/google/genai/tunings.rb', line 28

def get(name:, config: nil)
  raise "Tuning is only supported for Vertex AI" unless @api_client.vertexai
  response = @api_client.get("v1beta/#{name}")
  Types::TuningJob.new(JSON.parse(response.body))
end

#list(config: nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/google/genai/tunings.rb', line 34

def list(config: nil)
  raise "Tuning is only supported for Vertex AI" unless @api_client.vertexai
  
  list_request = ->(options) do
    path = "v1beta/tuningJobs"
    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: :tuningJobs,
    request: list_request,
    response: response,
    config: config,
    item_class: Types::TuningJob
  )
end