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.
- checksums.yaml +4 -4
- data/lib/tiny_gemini.rb +20 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bbd394b0cc2b9b63634b60360e8827c8fe5bb1e482dd2a3b05eb99f7bdef6d0
|
4
|
+
data.tar.gz: da9fe333b0e14e5cfe0167600a23e547e09b99d981ec7205528a657de326d86d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
|