gemini_cache 0.0.4 → 0.0.5
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 +14 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db225c3f8c93563f2bd4f1c8bd4fec3df644609ca9268bb7eeec996f42eaf48b
|
4
|
+
data.tar.gz: bb4f2198799740b227c16621396475f171b89806aae3f9644631651c22dfc049
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5f925f85d3c1bbe71b1b2c44febdce091ca508db753c26bc543613c81fffdefc2a4636f7bdb7ac06152f25d759bb805d6279e4a74d1bcf9452d18e7d0889f5c
|
7
|
+
data.tar.gz: 228a2728324e5d10210ec3c9691c1ce505cd3b13fa4914ba889bb6348dc24c43ddcf35c6c8821af6c583a3f0893a7d1467ce521bbf8bbec33454cd631e6fc420
|
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(
|
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:
|
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,8 @@ 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
|
+
def self.read_nokogiri_html(url) = Nokogiri::HTML(URI.open(url))
|
139
150
|
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
|
+
version: 0.0.5
|
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-
|
11
|
+
date: 2024-11-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|