gemini_cache 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/gemini_cache.rb +20 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16f6934eba6497750a226af8f1ec7e769ccb40da707fb066d459472461c4f8d3
4
- data.tar.gz: 13e80103252e7f59af3c313af528a2f4d300172d09e93d856beaa4b755069495
3
+ metadata.gz: bd9c1ef68b516dfab654ac65c1a211494e21573c772cc244dd13071cd951e097
4
+ data.tar.gz: caab21e5e9c2dccadc0dc332aeef23fd6a79978dcfdbbd96b3af341eb5809458
5
5
  SHA512:
6
- metadata.gz: f5719b1e1bd3ffa26d09bfd013a2bd1d1a1b80481c20aef57c93329e949c0ed113389c2fd926f344f62bc71a59bcf155742ddc7e2f0358c543c216fdc7117d95
7
- data.tar.gz: 6aaad0d3a575fb0219ab3568c8e346a0d345eab9ab8a83a1685b93548274db1c502ccb176200c860169a8aa8439955748e46679483eb934407117dde74cefa5a
6
+ metadata.gz: da9d5c70a85fb76adf656a8b53d53123ab480451e2042e6edc91d4a40c935bfd33cfc7430270f68cc56d8edc507b19ed54eaf743c1403c6e3735d8236dde29f8
7
+ data.tar.gz: 6644a2f79ff8013674136cb533fcf5df679d54987f806f7709d0e0f5de2dd20bcfb1bbb965bccfd3fee83753ad66635bfb0700874bdb5483a422c8553f7fe160
data/lib/gemini_cache.rb CHANGED
@@ -51,7 +51,7 @@ module GeminiCache
51
51
  def item.delete = GeminiCache.delete(name: self['name'])
52
52
  def item.set_ttl(ttl = 120) = GeminiCache.update(name: self['name'], content: { ttl: "#{ttl}s" })
53
53
 
54
- def item.generate_content(contents:)
54
+ def item.generate_content(contents:, generation_config: nil)
55
55
  conn = Faraday.new(
56
56
  url: 'https://generativelanguage.googleapis.com',
57
57
  headers: { 'Content-Type' => 'application/json' }
@@ -60,12 +60,16 @@ module GeminiCache
60
60
  f.options.open_timeout = 300 # timeout em segundos para abrir a conexão
61
61
  end
62
62
 
63
+ body = {
64
+ cached_content: self['name'],
65
+ contents:
66
+ }
67
+
68
+ body[:generation_config] = generation_config if !generation_config.nil?
69
+
63
70
  response = conn.post("/v1beta/models/#{self['model'].split('/').last}:generateContent") do |req|
64
71
  req.params['key'] = ENV.fetch('GEMINI_API_KEY')
65
- req.body = {
66
- cached_content: self['name'],
67
- contents:
68
- }.to_json
72
+ req.body = body.to_json
69
73
  end
70
74
 
71
75
  if response.status == 200
@@ -79,7 +83,9 @@ module GeminiCache
79
83
  raise "Erro na requisição: #{e.message}"
80
84
  end
81
85
 
82
- def item.single_prompt(prompt:) = generate_content(contents: [{ parts: [{ text: prompt }], role: 'user' }]).content
86
+ def item.single_prompt(prompt:, generation_config: nil)
87
+ generate_content(contents: [{ parts: [{ text: prompt }], role: 'user' }], generation_config:).content
88
+ end
83
89
 
84
90
  item
85
91
  end
@@ -122,4 +128,12 @@ module GeminiCache
122
128
  rescue Faraday::Error => e
123
129
  raise "Erro na requisição: #{e.message}"
124
130
  end
131
+
132
+ def self.delete_all
133
+ GeminiCache.list.each { |item| item.delete }
134
+ end
135
+
136
+ class << self
137
+ alias clear delete_all
138
+ end
125
139
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemini_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gedean Dias