tiny_gemini 1.0.1 → 1.0.3

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 +12 -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: 5fec31bc59d83171347e905341b6e09a3a8dbfe9f564214810fac9b6bd36cdcb
4
+ data.tar.gz: b26ca94d2f8122016cb73f194d016c72e5fb1163595908e163b259662e79b8b4
5
5
  SHA512:
6
- metadata.gz: 955d8e3bc0b12f934bfa44a66022ed345530a5b6f9302eeef858e8599f7bf7ed8ebaec84fba0345427bccf62045f3f075b8be1dbf6dd57ea53dc8b023b89cc85
7
- data.tar.gz: 0e7961437e74dc645bb35f88e8fa41930d6e2a9a3ac91583ed08e5e2a0dcdfaeec5bb4f5d15f0d150e08c753294d4ed0bad22038824a91c11aa9ed8ba6fb7ac2
6
+ metadata.gz: '0922057a519f8927f76cf9027eaba67d1dca70294f1ebeda174bf9e7a3cadd2a3f8f43a074a47bdf24b8108764ee81627432bff0f010f20f829990f1adf7f67a'
7
+ data.tar.gz: 7638fbe6bc05aa38c2ccb0cdbe5bded16bc471a5e21e65619d025d7d7675c35e3c0684dea436557952754197a1a758c19ae6aaa9926b63b81be7c9905d8eb82f
data/lib/tiny_gemini.rb CHANGED
@@ -59,6 +59,7 @@ 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
+
62
63
  request_body = body.to_json
63
64
 
64
65
  uri = URI("https://#{@host}#{@path}/#{@model}:#{@action}?key=#{@api_key}")
@@ -70,7 +71,17 @@ class TinyGemini
70
71
  raise TinyGeminiModelError, "Gemini API Error: #{response.code}\n#{JSON.pretty_generate(response.body)}"
71
72
  end
72
73
 
73
- JSON.parse(response.body)['candidates'].first.dig('content', 'parts').first['text']
74
+ # response and error handling
75
+ parsed_response = JSON.parse(response.body)
76
+ raise(TinyGeminiModelError, "No condidates in Gemini response") unless parsed_response['candidates']
77
+
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['text']
82
+ raise(TinyGeminiModelError, "Text response is nil or empty: `#{text_response.inspect}`") unless text_response.present?
83
+
84
+ text_response
74
85
  end
75
86
  end
76
87
 
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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Lunt