geminiext 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0217cac9967438f0bbd4fe0dc38b6c0aba1d21475b937c6b4d1b4d41d51a12b6
4
- data.tar.gz: df412fa82b43d42dcaca12b993cfa76f6c9e49dea76e55dfa9cbcddc79a9bee6
3
+ metadata.gz: 8584393659f6094698f8efc8f19d5bb2c1a1608641614cc2bbbf69734853328a
4
+ data.tar.gz: 586b5fb85e7b7074ead525b376379d79e01a471facf54c009b7575eb2dbabe10
5
5
  SHA512:
6
- metadata.gz: 884cdc51610f1d2beefd9884a4b779560adfff38c14deafc3bad84b3dc2ce84079cabf29eae88d96e6688d73dc25824d23eaea7fc2b379fac327de87974e29ea
7
- data.tar.gz: e9f69ffe68c4434738612884e54f89d5e471016ee1425846d374f9efa80b13e3fb4210f3f21a3b088e292861717fe0fa3f45473414d28307ec5b63781fe84b3b
6
+ metadata.gz: 20fc9f1d721df29f89f419e6ac9e9d76af4220b1e901e548562681f6d612f557f59e1a8415bb1a013575da14f055026a838b995096e2fce2bf566d4831b53731
7
+ data.tar.gz: 4d7b0de55589e664125455afc6c5a6a4fac115e610f4faa271a770e692b4ebbdd96e3a100c993fc2aeeadc9b93ce2dcd59152373ce0e6e8ee5eab425611091c3
@@ -0,0 +1,81 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ module GeminiExt
5
+ module Cache
6
+ def self.create(contents:, display_name:, model: 'gemini-1.5-flash-001', ttl: 600)
7
+ content = {
8
+ model: "models/#{model}",
9
+ display_name:,
10
+ contents:,
11
+ ttl: "#{ttl}s"
12
+ }.to_json
13
+
14
+ conn = Faraday.new(
15
+ url: 'https://generativelanguage.googleapis.com',
16
+ headers: { 'Content-Type' => 'application/json' }
17
+ )
18
+
19
+ response = conn.post('/v1beta/cachedContents') do |req|
20
+ req.params['key'] = ENV.fetch('GEMINI_API_KEY')
21
+ req.body = content
22
+ end
23
+
24
+ return JSON.parse(response.body) if response.status == 200
25
+
26
+ raise "Erro ao criar cache: #{response.status} - #{response.body}"
27
+ rescue Faraday::Error => e
28
+ raise "Erro na requisição: #{e.message}"
29
+ end
30
+
31
+ def self.list
32
+ conn = Faraday.new(
33
+ url: 'https://generativelanguage.googleapis.com',
34
+ headers: { 'Content-Type' => 'application/json' }
35
+ )
36
+
37
+ response = conn.get("/v1beta/cachedContents") do |req|
38
+ req.params['key'] = ENV.fetch('GEMINI_API_KEY')
39
+ end
40
+
41
+ JSON.parse(response.body)
42
+ rescue Faraday::Error => e
43
+ raise "Erro na requisição: #{e.message}"
44
+ end
45
+
46
+ def self.update(name:, content:)
47
+ conn = Faraday.new(
48
+ url: 'https://generativelanguage.googleapis.com',
49
+ headers: { 'Content-Type' => 'application/json' }
50
+ )
51
+
52
+ response = conn.patch("/v1beta/#{name}") do |req|
53
+ req.params['key'] = ENV.fetch('GEMINI_API_KEY')
54
+ req.body = content
55
+ end
56
+
57
+ return JSON.parse(response.body) if response.status == 200
58
+
59
+ raise "Erro ao atualizar cache: #{response.body}"
60
+ rescue Faraday::Error => e
61
+ raise "Erro na requisição: #{e.message}"
62
+ end
63
+
64
+ def self.delete(name:)
65
+ conn = Faraday.new(
66
+ url: 'https://generativelanguage.googleapis.com',
67
+ headers: { 'Content-Type' => 'application/json' }
68
+ )
69
+
70
+ response = conn.delete("/v1beta/#{name}") do |req|
71
+ req.params['key'] = ENV.fetch('GEMINI_API_KEY')
72
+ end
73
+
74
+ return true if response.status == 200
75
+
76
+ raise "Erro ao deletar cache: #{response.body}"
77
+ rescue Faraday::Error => e
78
+ raise "Erro na requisição: #{e.message}"
79
+ end
80
+ end
81
+ end
data/lib/geminiext.rb CHANGED
@@ -1,15 +1,17 @@
1
1
  require 'gemini-ai'
2
+ #require 'faraday'
2
3
 
3
- # require 'geminiext/model'
4
+ require 'geminiext/cache'
4
5
  # require 'geminiext/messages'
5
6
  # require 'geminiext/response_extender'
6
7
 
7
8
  module GeminiExt
8
9
  MAX_TOKENS = ENV.fetch('GEMINI_MAX_TOKENS', 8_192).to_i
9
-
10
+
10
11
  def self.new(model: 'gemini-1.5-flash-001')
11
12
  Gemini.new(load_config(model: model))
12
13
  end
14
+
13
15
 
14
16
  def self.load_config(model: 'gemini-1.5-flash-001')
15
17
  {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geminiext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gedean Dias
@@ -46,9 +46,10 @@ extra_rdoc_files: []
46
46
  files:
47
47
  - README.md
48
48
  - lib/geminiext.rb
49
- - lib/openaiext/messages.rb.disabled
50
- - lib/openaiext/model.rb.disabled
51
- - lib/openaiext/response_extender.rb.disabled
49
+ - lib/geminiext/cache.rb
50
+ - lib/geminiext/messages.rb.disabled
51
+ - lib/geminiext/model.rb.disabled
52
+ - lib/geminiext/response_extender.rb.disabled
52
53
  homepage: https://github.com/gedean/geminiext
53
54
  licenses:
54
55
  - MIT
File without changes
File without changes