gemini_cache 0.0.3 → 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 +12 -6
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '04685d49a72d97ba748888a2c1a90ffae49dd52d5bdea582e5cc93c5278ee05d'
4
- data.tar.gz: 1fbf73ef5d37c9eeffee36e2667faf3846a326a217c4ae3dcc9bd6f781bec0ed
3
+ metadata.gz: bd9c1ef68b516dfab654ac65c1a211494e21573c772cc244dd13071cd951e097
4
+ data.tar.gz: caab21e5e9c2dccadc0dc332aeef23fd6a79978dcfdbbd96b3af341eb5809458
5
5
  SHA512:
6
- metadata.gz: 9397ae965759c13a8b4f23cd26e17fbd66807cf6ef09ec299b5ff6695fdbc32f74c9858574f727da489d7039d761be2d900220c39d8d3d9a6cfb22360eb6bcdb
7
- data.tar.gz: efa123d59d17f71e2193b82de461b0648d5a887377175331993b9bc48ef17872b0987f9a9622311c40062a6639f3c72e792d69b5a2345568f4985601eb0de624
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
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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gedean Dias