Class: Google::Genai::Caches

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

Instance Method Summary collapse

Constructor Details

#initialize(api_client) ⇒ Caches

Returns a new instance of Caches.



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

def initialize(api_client)
  @api_client = api_client
end

Instance Method Details

#create(model:, config:) ⇒ Object



13
14
15
16
# File 'lib/google/genai/caches.rb', line 13

def create(model:, config:)
  response = @api_client.request(:post, "v1beta/cachedContents", body: { model: model }.merge(config))
  Types::CachedContent.new(JSON.parse(response.body))
end

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



49
50
51
52
# File 'lib/google/genai/caches.rb', line 49

def delete(name:, config: nil)
  @api_client.delete("v1beta/#{name}")
  nil
end

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



18
19
20
21
# File 'lib/google/genai/caches.rb', line 18

def get(name:, config: nil)
  response = @api_client.get("v1beta/#{name}")
  Types::CachedContent.new(JSON.parse(response.body))
end

#list(config: nil) ⇒ Object



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

def list(config: nil)
  list_request = ->(options) do
    path = "v1beta/cachedContents"
    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: :cachedContents,
    request: list_request,
    response: response,
    config: config,
    item_class: Types::CachedContent
  )
end

#update(name:, config:) ⇒ Object



44
45
46
47
# File 'lib/google/genai/caches.rb', line 44

def update(name:, config:)
  response = @api_client.request(:patch, "v1beta/#{name}", body: config)
  Types::CachedContent.new(JSON.parse(response.body))
end