gemini_cache 0.0.4 → 0.0.6

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 +19 -3
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd9c1ef68b516dfab654ac65c1a211494e21573c772cc244dd13071cd951e097
4
- data.tar.gz: caab21e5e9c2dccadc0dc332aeef23fd6a79978dcfdbbd96b3af341eb5809458
3
+ metadata.gz: 276c3ca26a6767aad15542bae697d58b6f6c546827c668bc922632d391ea0598
4
+ data.tar.gz: 672b16527768229e7d84819b7d2b2844c41fe57c57e1bf1171414c182e8cc101
5
5
  SHA512:
6
- metadata.gz: da9d5c70a85fb76adf656a8b53d53123ab480451e2042e6edc91d4a40c935bfd33cfc7430270f68cc56d8edc507b19ed54eaf743c1403c6e3735d8236dde29f8
7
- data.tar.gz: 6644a2f79ff8013674136cb533fcf5df679d54987f806f7709d0e0f5de2dd20bcfb1bbb965bccfd3fee83753ad66635bfb0700874bdb5483a422c8553f7fe160
6
+ metadata.gz: 69700db12b8f6c8e78e3a3577843bc01f6fda112aec173653419c0674dd91baa59aee0a03be37eda62d9f1cf07e8a3892c47f28ec29d7a539d29b0d984988e3e
7
+ data.tar.gz: 6992ec6e1537b00dc69de4afe0f13457a75758d6327f8c2bafecd9fb868e833d26a499363649e78e08ba9ac680641453fd572aaa52e4075ebac16885897e57a8
data/lib/gemini_cache.rb CHANGED
@@ -1,12 +1,16 @@
1
1
  require 'faraday'
2
+ require 'open-uri'
3
+ require 'nokogiri'
2
4
  require 'json'
3
5
 
4
6
  module GeminiCache
5
- def self.create(contents:, display_name:, model: 'gemini-1.5-flash-8b', ttl: 600)
7
+ def self.create(parts:, display_name:, model: 'gemini-1.5-flash-8b', ttl: 600)
8
+ raise "Cache name already exist: '#{display_name}'" if GeminiCache.get(display_name:)
9
+
6
10
  content = {
7
11
  model: "models/#{model}",
8
12
  display_name:,
9
- contents:,
13
+ contents: [parts:, role: 'user'],
10
14
  ttl: "#{ttl}s"
11
15
  }.to_json
12
16
 
@@ -83,7 +87,10 @@ module GeminiCache
83
87
  raise "Erro na requisição: #{e.message}"
84
88
  end
85
89
 
86
- def item.single_prompt(prompt:, generation_config: nil)
90
+ def item.single_prompt(prompt:, generation_config: :accurate_mode)
91
+ # accurate_mode: less creative, more accurate
92
+ generation_config = { temperature: 0, topP: 0, topK: 1 } if generation_config.eql?(:accurate_mode)
93
+
87
94
  generate_content(contents: [{ parts: [{ text: prompt }], role: 'user' }], generation_config:).content
88
95
  end
89
96
 
@@ -136,4 +143,13 @@ module GeminiCache
136
143
  class << self
137
144
  alias clear delete_all
138
145
  end
146
+
147
+ def self.read_local_file(file_path) = Base64.strict_encode64(File.read(file_path))
148
+ def self.read_remote_file(file_url) = Base64.strict_encode64(URI.open(file_url).read)
149
+
150
+ def self.read_nokogiri_html(url, default_remover: true)
151
+ doc = Nokogiri::HTML(URI.open(url))
152
+ %w[script style].each { |element| doc.css(element).each(&:remove) } if default_remover
153
+ doc
154
+ end
139
155
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gemini_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gedean Dias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-11-10 00:00:00.000000000 Z
11
+ date: 2024-11-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday