Class: Google::Genai::Batches

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

Instance Method Summary collapse

Constructor Details

#initialize(api_client) ⇒ Batches

Returns a new instance of Batches.



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

def initialize(api_client)
  @api_client = api_client
end

Instance Method Details

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



58
59
60
61
62
# File 'lib/google/genai/batches.rb', line 58

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

#create(model:, src:, config: nil) ⇒ Object



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

def create(model:, src:, config: nil)
  raise "Batches is only supported for Vertex AI" unless @api_client.vertexai

  body = {
    model: model,
    inputConfig: {
      instancesFormat: src.is_a?(String) && src.start_with?('bq://') ? 'bigquery' : 'jsonl',
      gcsSource: { uris: [src] }
    }
  }
  # TODO: Add other config options

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

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



64
65
66
67
68
# File 'lib/google/genai/batches.rb', line 64

def delete(name:, config: nil)
  raise "Batches is only supported for Vertex AI" unless @api_client.vertexai
  @api_client.delete("v1beta/#{name}")
  nil
end

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



29
30
31
32
33
# File 'lib/google/genai/batches.rb', line 29

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

#list(config: nil) ⇒ Object



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

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