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.
- checksums.yaml +4 -4
- data/lib/gemini_cache.rb +20 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd9c1ef68b516dfab654ac65c1a211494e21573c772cc244dd13071cd951e097
|
4
|
+
data.tar.gz: caab21e5e9c2dccadc0dc332aeef23fd6a79978dcfdbbd96b3af341eb5809458
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|