tiny_gemini 1.0.1 → 1.0.2

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 +20 -1
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab7e00903ada0199cff54253ad7f1461818b6c55947980bc67cde4aa7d641da5
4
- data.tar.gz: cfa8b05416999c1b5d5095ae8f06d800ca709e9ad7d93f478f50c52199824894
3
+ metadata.gz: 1bbd394b0cc2b9b63634b60360e8827c8fe5bb1e482dd2a3b05eb99f7bdef6d0
4
+ data.tar.gz: da9fe333b0e14e5cfe0167600a23e547e09b99d981ec7205528a657de326d86d
5
5
  SHA512:
6
- metadata.gz: 955d8e3bc0b12f934bfa44a66022ed345530a5b6f9302eeef858e8599f7bf7ed8ebaec84fba0345427bccf62045f3f075b8be1dbf6dd57ea53dc8b023b89cc85
7
- data.tar.gz: 0e7961437e74dc645bb35f88e8fa41930d6e2a9a3ac91583ed08e5e2a0dcdfaeec5bb4f5d15f0d150e08c753294d4ed0bad22038824a91c11aa9ed8ba6fb7ac2
6
+ metadata.gz: 7ec88cdc3b50604ed4fff7bb61704324d07dbf7d0b2016312e98e8ed440d9a6672fd73253007854b4c2a3aa70ff671d8165d10a89275400838613bbe542b53f0
7
+ data.tar.gz: 9c6f41d624e1bf930097636c19dc8cb4613ed15255db44b54fe255f9089289e1f397de73c429c1f065fa0786044c1936efd6f236eef7a7e08f2e00d0ad712b91
data/lib/tiny_gemini.rb CHANGED
@@ -59,6 +59,15 @@ class TinyGemini
59
59
  def chat(messages)
60
60
  body = { contents: messages }
61
61
  body.merge!(system_instruction: { parts: { text: @system_instruction } }) if @system_instruction
62
+ body.merge!({
63
+ safetySettings: [
64
+ {
65
+ category: "HARM_CATEGORY_SEXUALLY_EXPLICIT",
66
+ threshold: "BLOCK_NONE"
67
+ }
68
+ ]
69
+ })
70
+
62
71
  request_body = body.to_json
63
72
 
64
73
  uri = URI("https://#{@host}#{@path}/#{@model}:#{@action}?key=#{@api_key}")
@@ -70,7 +79,17 @@ class TinyGemini
70
79
  raise TinyGeminiModelError, "Gemini API Error: #{response.code}\n#{JSON.pretty_generate(response.body)}"
71
80
  end
72
81
 
73
- JSON.parse(response.body)['candidates'].first.dig('content', 'parts').first['text']
82
+ # response and error handling
83
+ parsed_response = JSON.parse(response.body)
84
+ raise(TinyGeminiModelError, "No condidates in Gemini response") unless parsed_response['candidates']
85
+
86
+ first_candidate_response = parsed_response['candidates'].first
87
+ raise(TinyGeminiModelError, "No first candidate response in Gemini response") unless first_candidate_response
88
+
89
+ text_response = first_candidate_response&.dig('content', 'parts')&.first['text']
90
+ raise(TinyGeminiModelError, "Text response is nil or empty: `#{text_response.inspect}`") unless text_response.present?
91
+
92
+ text_response
74
93
  end
75
94
  end
76
95
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_gemini
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt