tiny_gemini 2.1.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tiny_gemini.rb +4 -8
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 175b20b86e78addef75bb9d649eefc0b28948bc8404ee5d576c0987345cf71b7
4
- data.tar.gz: e274e337544f79f5fd77dcb22e0580f5edb0bc1f20d9451a5e8c04ab3cef4141
3
+ metadata.gz: b5f56e4cbc05e3d459f13871f6cd6bdddd3468b7cea23777c8361b08f802a07c
4
+ data.tar.gz: a1ef17332bd9433a72dce319e0048a5d34826fc8685e985b28088a0c80d67a6e
5
5
  SHA512:
6
- metadata.gz: ca9e748c8b91c4d0a321e2cfc8b739226784286f04f6a2cfa3dcc76fef81a1ba4b89fc89ef4e59eb6dbdefdbb96ff3d55ef467b38a53bbfe4e6083695291f6b1
7
- data.tar.gz: ee42d1d339f841fe9021db7c45b5a82c8f7eb7268a387ca9d0454d29b81c94bbda11abb225fbf63c613b2e917af128de99deebe79a5903b8880bea5b5dc9d39a
6
+ metadata.gz: 9d70f2652d4ffee8a1022e456b11f588034c9a8b9f6e090628392463bc924d172f8f33f2354fb6dd264a9f02c115989a674c2a90a5d770de134faf6be0bdce8f
7
+ data.tar.gz: a876b8793468acbd501491098acf12c23f696c529853c81c289ca530f9c74018220753ccdc465476184ede058aabfbe819ac9cc38cac18caff7912efed3f0191
data/lib/tiny_gemini.rb CHANGED
@@ -24,6 +24,7 @@ class TinyGemini
24
24
  end
25
25
 
26
26
  # sends a request to POST generateContent
27
+ # returns the parsed JSON reply
27
28
  #
28
29
  # messages: an array of hashes in the following format:
29
30
  # [
@@ -56,9 +57,10 @@ class TinyGemini
56
57
  # NOTE: if you want the model to impersonate a character (i.e. a talking cat)
57
58
  # you need to have set the `system_instruction` parameter when initializing
58
59
  # this class to make that work
59
- def prompt(messages)
60
+ def prompt(messages, safety_settings=nil)
60
61
  body = { contents: messages }
61
62
  body.merge!(system_instruction: { parts: { text: @system_instruction } }) if @system_instruction
63
+ body.merge!(safety_settings: safety_settings) if safety_settings
62
64
 
63
65
  request_body = body.to_json
64
66
 
@@ -75,13 +77,7 @@ class TinyGemini
75
77
  parsed_response = JSON.parse(response.body)
76
78
  raise(TinyGeminiModelError, "No condidates in Gemini response") unless parsed_response['candidates']
77
79
 
78
- first_candidate_response = parsed_response['candidates'].first
79
- raise(TinyGeminiModelError, "No first candidate response in Gemini response") unless first_candidate_response
80
-
81
- text_response = first_candidate_response&.dig('content', 'parts')&.first&.dig('text')&.strip
82
- raise(TinyGeminiModelError, "Text response is nil or empty: `#{text_response.inspect}`") if text_response.nil? || text_response.length == 0
83
-
84
- text_response
80
+ parsed_response
85
81
  end
86
82
  end
87
83
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_gemini
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-01 00:00:00.000000000 Z
11
+ date: 2024-09-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: a tiny gem for using Google Gemini's generative models for chat
14
14
  email: jefflunt@gmail.com