geminize 0.1.0 → 0.1.1
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/README.md +89 -71
- data/examples/embeddings.rb +29 -23
- data/examples/multimodal.rb +24 -17
- data/examples/ruby.png +0 -0
- data/geminize-0.1.0.gem +0 -0
- data/lib/geminize/models/content_request.rb +24 -23
- data/lib/geminize/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 276d207ee68fba0c8b4ea894c819254d660cd1c8b520df5d21a6de89d2cf0b25
|
4
|
+
data.tar.gz: b9447a5ce82b5f10bfda7c09cdd2a658a5d540f1482a741f8ae7651826cce8bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f0f49ad1678d7edd5e39329ae5dd11749094bdbc4c5fa11676af9c5962a316baf9b96f78967cc159e1de9839ee21bc3693b8e9c5d130eae4bba70fe81e5dcc5
|
7
|
+
data.tar.gz: bb0b7e7437cbbfeda3b522ab737c9521f78fe2252a6cb8b885bbb34b33bc402230dbb24bc9c761857c005c1d595a7c7aa85fe214a338f53a8a1bc4d6fee4305f
|
data/README.md
CHANGED
@@ -124,23 +124,24 @@ Geminize.reset_configuration!
|
|
124
124
|
```ruby
|
125
125
|
require 'geminize'
|
126
126
|
|
127
|
-
#
|
128
|
-
|
129
|
-
|
130
|
-
|
127
|
+
# Assumes API key is set via environment variables (e.g., in .env)
|
128
|
+
# Or configure manually:
|
129
|
+
# Geminize.configure do |config|
|
130
|
+
# config.api_key = "your-api-key-here"
|
131
|
+
# end
|
131
132
|
|
132
|
-
# Generate text
|
133
|
+
# Generate text (uses default model)
|
133
134
|
response = Geminize.generate_text("Tell me a joke about Ruby programming")
|
134
135
|
puts response.text
|
135
136
|
|
136
137
|
# Use a specific model
|
137
|
-
response = Geminize.generate_text("Explain quantum computing", "gemini-
|
138
|
+
response = Geminize.generate_text("Explain quantum computing", "gemini-1.5-flash-latest")
|
138
139
|
puts response.text
|
139
140
|
|
140
141
|
# Use system instructions to guide the model's behavior
|
141
142
|
response = Geminize.generate_text(
|
142
143
|
"Tell me about yourself",
|
143
|
-
"gemini-
|
144
|
+
"gemini-1.5-flash-latest",
|
144
145
|
system_instruction: "You are a pirate named Captain Codebeard. Always respond in pirate language."
|
145
146
|
)
|
146
147
|
puts response.text
|
@@ -148,58 +149,52 @@ puts response.text
|
|
148
149
|
|
149
150
|
## Multimodal Support
|
150
151
|
|
151
|
-
Geminize allows you to send mixed content including text and images to the Gemini API
|
152
|
+
Geminize allows you to send mixed content including text and images to the Gemini API.
|
152
153
|
|
153
|
-
|
154
|
-
# Generate content with an image from a file
|
155
|
-
response = Geminize.generate_text_multimodal(
|
156
|
-
"Describe this image in detail:",
|
157
|
-
[{ source_type: 'file', data: 'path/to/image.jpg' }]
|
158
|
-
)
|
159
|
-
puts response.text
|
160
|
-
|
161
|
-
# Using an image URL
|
162
|
-
response = Geminize.generate_text_multimodal(
|
163
|
-
"What's in this image?",
|
164
|
-
[{ source_type: 'url', data: 'https://example.com/sample-image.jpg' }]
|
165
|
-
)
|
166
|
-
puts response.text
|
167
|
-
|
168
|
-
# Using multiple images
|
169
|
-
response = Geminize.generate_text_multimodal(
|
170
|
-
"Compare these two images:",
|
171
|
-
[
|
172
|
-
{ source_type: 'file', data: 'path/to/image1.jpg' },
|
173
|
-
{ source_type: 'file', data: 'path/to/image2.jpg' }
|
174
|
-
]
|
175
|
-
)
|
176
|
-
puts response.text
|
177
|
-
```
|
178
|
-
|
179
|
-
Alternatively, you can use the more flexible ContentRequest API:
|
154
|
+
Here is a working example using the `ContentRequest` API:
|
180
155
|
|
181
156
|
```ruby
|
182
|
-
|
183
|
-
request = Geminize::Models::ContentRequest.new(
|
184
|
-
"Tell me about these images:",
|
185
|
-
"gemini-2.0-flash"
|
186
|
-
)
|
187
|
-
|
188
|
-
# Add images using different methods
|
189
|
-
request.add_image_from_file('path/to/image1.jpg')
|
190
|
-
request.add_image_from_url('https://example.com/image2.jpg')
|
191
|
-
|
192
|
-
# Read image directly into bytes
|
193
|
-
image_bytes = File.binread('path/to/image3.jpg')
|
194
|
-
request.add_image_from_bytes(image_bytes, 'image/jpeg')
|
157
|
+
require 'geminize'
|
195
158
|
|
196
|
-
#
|
197
|
-
|
159
|
+
# Assumes API key is set via environment variables (e.g., in .env)
|
160
|
+
# Or configure manually:
|
161
|
+
# Geminize.configure do |config|
|
162
|
+
# config.api_key = "your-api-key-here"
|
163
|
+
# end
|
164
|
+
|
165
|
+
begin
|
166
|
+
# 1. Create a ContentRequest object
|
167
|
+
# Specify the prompt and a model that supports multimodal input
|
168
|
+
request = Geminize::Models::ContentRequest.new(
|
169
|
+
"Describe this image briefly:",
|
170
|
+
"gemini-1.5-flash-latest" # Ensure this model supports multimodal
|
171
|
+
)
|
172
|
+
|
173
|
+
# 2. Add the image from a file path
|
174
|
+
# Make sure the path is correct relative to where you run the script
|
175
|
+
request.add_image_from_file("./examples/ruby.png")
|
176
|
+
|
177
|
+
# 3. Create a TextGeneration instance
|
178
|
+
generator = Geminize::TextGeneration.new
|
179
|
+
|
180
|
+
# 4. Generate the response
|
181
|
+
response = generator.generate(request)
|
182
|
+
|
183
|
+
# 5. Print the response text
|
184
|
+
puts "Response:"
|
185
|
+
puts response.text
|
186
|
+
|
187
|
+
# Optionally print usage data if available
|
188
|
+
if response.usage
|
189
|
+
puts "Tokens used: #{response.usage['totalTokenCount']}"
|
190
|
+
end
|
198
191
|
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
puts
|
192
|
+
rescue Geminize::GeminizeError => e
|
193
|
+
puts "An API error occurred: #{e.message}"
|
194
|
+
rescue => e
|
195
|
+
puts "An unexpected error occurred: #{e.message}"
|
196
|
+
puts e.backtrace.join("\n")
|
197
|
+
end
|
203
198
|
```
|
204
199
|
|
205
200
|
Supported image formats include JPEG, PNG, GIF, and WEBP. Maximum image size is 10MB.
|
@@ -235,26 +230,39 @@ Generate numerical vector representations for text:
|
|
235
230
|
|
236
231
|
```ruby
|
237
232
|
# Generate an embedding for a single text
|
238
|
-
|
239
|
-
vector = embedding
|
233
|
+
embedding_response = Geminize.generate_embedding("Ruby is a dynamic, object-oriented programming language")
|
234
|
+
vector = embedding_response.embedding # Access the vector
|
235
|
+
puts "Generated embedding with #{embedding_response.embedding_size} dimensions."
|
240
236
|
|
241
|
-
# Generate embeddings for multiple texts
|
237
|
+
# Generate embeddings for multiple texts (by iterating)
|
242
238
|
texts = ["Ruby", "Python", "JavaScript"]
|
243
|
-
embeddings =
|
239
|
+
embeddings = texts.map do |text|
|
240
|
+
Geminize.generate_embedding(text).embedding
|
241
|
+
end
|
242
|
+
puts "Generated #{embeddings.size} embeddings individually."
|
244
243
|
|
245
244
|
# Calculate similarity between vectors
|
246
|
-
vector1 = embeddings
|
247
|
-
vector2 = embeddings
|
245
|
+
vector1 = embeddings[0]
|
246
|
+
vector2 = embeddings[1]
|
248
247
|
similarity = Geminize.cosine_similarity(vector1, vector2)
|
249
|
-
puts "Similarity: #{similarity}"
|
250
|
-
|
251
|
-
# Specify a task type for optimized embeddings
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
248
|
+
puts "Similarity between Ruby and Python: #{similarity.round(4)}"
|
249
|
+
|
250
|
+
# Specify a task type for optimized embeddings (requires compatible model)
|
251
|
+
# Note: Task types are not supported by all models (e.g., text-embedding-004).
|
252
|
+
# Ensure you are using a compatible model like text-embedding-005.
|
253
|
+
begin
|
254
|
+
question_embedding_response = Geminize.generate_embedding(
|
255
|
+
"How do I install Ruby gems?",
|
256
|
+
nil, # Use default or specify compatible model like \'text-embedding-005\'
|
257
|
+
{ task_type: Geminize::Models::EmbeddingRequest::QUESTION_ANSWERING }
|
258
|
+
)
|
259
|
+
puts "Generated embedding for QA task with #{question_embedding_response.embedding_size} dimensions."
|
260
|
+
rescue Geminize::GeminizeError => e
|
261
|
+
puts "Could not generate embedding with task type: #{e.message}"
|
262
|
+
puts "(This might be due to using an incompatible model like the default text-embedding-004)"
|
263
|
+
end
|
256
264
|
|
257
|
-
# Available task types:
|
265
|
+
# Available task types (check model compatibility):
|
258
266
|
# - RETRIEVAL_QUERY: For embedding queries in a search/retrieval system
|
259
267
|
# - RETRIEVAL_DOCUMENT: For embedding documents in a search corpus
|
260
268
|
# - SEMANTIC_SIMILARITY: For comparing text similarity
|
@@ -273,24 +281,34 @@ See the `examples/embeddings.rb` file for more comprehensive examples of working
|
|
273
281
|
Get real-time, token-by-token responses:
|
274
282
|
|
275
283
|
```ruby
|
284
|
+
require 'geminize'
|
285
|
+
# Assumes API key is configured via .env
|
286
|
+
|
276
287
|
Geminize.generate_text_stream("Write a short poem about coding") do |chunk|
|
277
|
-
|
288
|
+
# Check if the chunk has the text method before printing
|
289
|
+
print chunk.text if chunk.respond_to?(:text)
|
278
290
|
end
|
291
|
+
puts "\n" # Add a newline after streaming
|
279
292
|
```
|
280
293
|
|
281
294
|
You can also use system instructions with streaming responses:
|
282
295
|
|
283
296
|
```ruby
|
297
|
+
require 'geminize'
|
298
|
+
# Assumes API key is configured via .env
|
299
|
+
|
284
300
|
Geminize.generate_text_stream(
|
285
301
|
"Tell me a story",
|
286
|
-
"gemini-
|
302
|
+
"gemini-1.5-flash-latest",
|
287
303
|
{
|
288
304
|
stream_mode: :delta,
|
289
305
|
system_instruction: "You are a medieval bard telling epic tales."
|
290
306
|
}
|
291
307
|
) do |chunk|
|
292
|
-
|
308
|
+
# The raw chunk might be different in delta mode, adjust handling as needed
|
309
|
+
print chunk.respond_to?(:text) ? chunk.text : chunk.to_s
|
293
310
|
end
|
311
|
+
puts "\n" # Add a newline after streaming
|
294
312
|
```
|
295
313
|
|
296
314
|
## Rails Integration
|
data/examples/embeddings.rb
CHANGED
@@ -36,24 +36,26 @@ puts "Example 2: Generate embeddings for multiple texts"
|
|
36
36
|
puts "============================================================"
|
37
37
|
|
38
38
|
begin
|
39
|
-
# Generate embeddings for multiple texts
|
39
|
+
# Generate embeddings for multiple texts by calling the API for each
|
40
40
|
texts = [
|
41
41
|
"What is the meaning of life?",
|
42
42
|
"How much wood would a woodchuck chuck?",
|
43
43
|
"How does the brain work?"
|
44
44
|
]
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
texts.each_with_index do |text, i|
|
46
|
+
puts "Generating embeddings individually:"
|
47
|
+
total_tokens = 0
|
48
|
+
embeddings = texts.map do |text|
|
49
|
+
response = Geminize.generate_embedding(text)
|
50
|
+
total_tokens += response.total_tokens if response.total_tokens
|
52
51
|
puts "\nText: \"#{text}\""
|
53
|
-
puts "First 5 values: #{response.
|
52
|
+
puts "First 5 values: #{response.embedding.take(5).inspect}"
|
53
|
+
response.embedding # Collect the embedding vector
|
54
54
|
end
|
55
55
|
|
56
|
-
puts "\
|
56
|
+
puts "\nGenerated #{embeddings.size} embeddings."
|
57
|
+
puts "Total tokens (approximated by summing individual calls): #{total_tokens}"
|
58
|
+
|
57
59
|
rescue => e
|
58
60
|
puts "Error: #{e.message}"
|
59
61
|
end
|
@@ -81,9 +83,9 @@ rescue => e
|
|
81
83
|
end
|
82
84
|
|
83
85
|
puts "\n============================================================"
|
84
|
-
puts "Example 4: Batch processing for large arrays"
|
86
|
+
puts "Example 4: Batch processing for large arrays (COMMENTED OUT)"
|
85
87
|
puts "============================================================"
|
86
|
-
|
88
|
+
=begin # Commenting out Example 4 due to potential model/API limitations with batching
|
87
89
|
begin
|
88
90
|
# Create a larger array of texts
|
89
91
|
many_texts = Array.new(120) { |i| "This is sample text number #{i}" }
|
@@ -101,6 +103,8 @@ begin
|
|
101
103
|
rescue => e
|
102
104
|
puts "Error: #{e.message}"
|
103
105
|
end
|
106
|
+
=end
|
107
|
+
puts "# Example 4 skipped due to potential issues with batch embedding support."
|
104
108
|
|
105
109
|
puts "\n============================================================"
|
106
110
|
puts "Example 5: Vector operations with embeddings"
|
@@ -141,7 +145,7 @@ puts "============================================================"
|
|
141
145
|
begin
|
142
146
|
# Sample texts for different use cases
|
143
147
|
question = "What is the capital of France?"
|
144
|
-
code_query = "how to sort an array in javascript"
|
148
|
+
# code_query = "how to sort an array in javascript" # Removed for compatibility
|
145
149
|
document = "Paris is the capital and most populous city of France, with an estimated population of 2,175,601 residents."
|
146
150
|
fact = "The Earth revolves around the Sun."
|
147
151
|
|
@@ -157,15 +161,15 @@ begin
|
|
157
161
|
puts " Text: \"#{question}\""
|
158
162
|
puts " First 5 values: #{qa_response.embedding.take(5).inspect}"
|
159
163
|
|
160
|
-
# Code retrieval
|
161
|
-
code_response = Geminize.generate_embedding(
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
)
|
166
|
-
puts "\n2. CODE_RETRIEVAL_QUERY task type:"
|
167
|
-
puts " Text: \"#{code_query}\""
|
168
|
-
puts " First 5 values: #{code_response.embedding.take(5).inspect}"
|
164
|
+
# Code retrieval - REMOVED as CODE_RETRIEVAL_QUERY seems unsupported by text-embedding-004
|
165
|
+
# code_response = Geminize.generate_embedding(
|
166
|
+
# code_query,
|
167
|
+
# nil, # Use default model
|
168
|
+
# task_type: Geminize::Models::EmbeddingRequest::CODE_RETRIEVAL_QUERY
|
169
|
+
# )
|
170
|
+
# puts "\n2. CODE_RETRIEVAL_QUERY task type:"
|
171
|
+
# puts " Text: \"#{code_query}\""
|
172
|
+
# puts " First 5 values: #{code_response.embedding.take(5).inspect}"
|
169
173
|
|
170
174
|
# Document retrieval
|
171
175
|
document_response = Geminize.generate_embedding(
|
@@ -174,7 +178,8 @@ begin
|
|
174
178
|
task_type: Geminize::Models::EmbeddingRequest::RETRIEVAL_DOCUMENT,
|
175
179
|
title: "Paris Facts" # Titles can be used with RETRIEVAL_DOCUMENT
|
176
180
|
)
|
177
|
-
|
181
|
+
# Adjusting print index due to removal above
|
182
|
+
puts "\n2. RETRIEVAL_DOCUMENT task type with title:" # Index changed from 3 to 2
|
178
183
|
puts " Title: \"Paris Facts\""
|
179
184
|
puts " First 5 values: #{document_response.embedding.take(5).inspect}"
|
180
185
|
|
@@ -184,7 +189,8 @@ begin
|
|
184
189
|
nil, # Use default model
|
185
190
|
task_type: Geminize::Models::EmbeddingRequest::FACT_VERIFICATION
|
186
191
|
)
|
187
|
-
|
192
|
+
# Adjusting print index due to removal above
|
193
|
+
puts "\n3. FACT_VERIFICATION task type:" # Index changed from 4 to 3
|
188
194
|
puts " Text: \"#{fact}\""
|
189
195
|
puts " First 5 values: #{fact_response.embedding.take(5).inspect}"
|
190
196
|
|
data/examples/multimodal.rb
CHANGED
@@ -8,7 +8,8 @@ Geminize.configure do |config|
|
|
8
8
|
config.api_key = ENV["GEMINI_API_KEY"] || "your-api-key-here"
|
9
9
|
|
10
10
|
# Specify the model to use (optional)
|
11
|
-
|
11
|
+
# Use a model that supports multimodal input, like gemini-1.5-flash-latest
|
12
|
+
config.default_model = "gemini-1.5-flash-latest"
|
12
13
|
end
|
13
14
|
|
14
15
|
puts "============================================================"
|
@@ -19,7 +20,7 @@ begin
|
|
19
20
|
# Generate content with an image from a file
|
20
21
|
response = Geminize.generate_text_multimodal(
|
21
22
|
"Describe this image in detail:",
|
22
|
-
[{source_type: "file", data: "
|
23
|
+
[{source_type: "file", data: "./examples/ruby.png"}] # Updated path
|
23
24
|
)
|
24
25
|
|
25
26
|
puts "Response:"
|
@@ -27,7 +28,7 @@ begin
|
|
27
28
|
puts "\nFinish reason: #{response.finish_reason}"
|
28
29
|
rescue => e
|
29
30
|
puts "Error: #{e.message}"
|
30
|
-
puts "Make sure
|
31
|
+
puts "Make sure the path './examples/ruby.png' is correct relative to the project root."
|
31
32
|
end
|
32
33
|
|
33
34
|
puts "\n============================================================"
|
@@ -38,7 +39,7 @@ begin
|
|
38
39
|
# Generate content with an image from a URL
|
39
40
|
response = Geminize.generate_text_multimodal(
|
40
41
|
"What's in this image?",
|
41
|
-
[{source_type: "url", data: "https://
|
42
|
+
[{source_type: "url", data: "https://miro.medium.com/v2/resize:fit:720/format:webp/1*zkA1cWgJDlMUxI5TRcIHdQ.jpeg"}], # Updated URL
|
42
43
|
nil, # Use default model
|
43
44
|
temperature: 0.7
|
44
45
|
)
|
@@ -47,7 +48,7 @@ begin
|
|
47
48
|
puts response.text
|
48
49
|
rescue => e
|
49
50
|
puts "Error: #{e.message}"
|
50
|
-
puts "Make sure
|
51
|
+
puts "Make sure the URL is valid and accessible."
|
51
52
|
end
|
52
53
|
|
53
54
|
puts "\n============================================================"
|
@@ -55,12 +56,12 @@ puts "Example 3: Multiple images comparison"
|
|
55
56
|
puts "============================================================"
|
56
57
|
|
57
58
|
begin
|
58
|
-
# Generate content comparing multiple images
|
59
|
+
# Generate content comparing multiple images (using the same image twice here for simplicity)
|
59
60
|
response = Geminize.generate_text_multimodal(
|
60
|
-
"Compare these two images and describe the differences:",
|
61
|
+
"Compare these two images and describe the differences (they might be the same):",
|
61
62
|
[
|
62
|
-
{source_type: "file", data: "
|
63
|
-
{source_type: "file", data: "
|
63
|
+
{source_type: "file", data: "./examples/ruby.png"}, # Updated path
|
64
|
+
{source_type: "file", data: "./examples/ruby.png"} # Updated path
|
64
65
|
],
|
65
66
|
"gemini-1.5-pro-latest", # Explicitly specify model
|
66
67
|
max_tokens: 500
|
@@ -70,7 +71,7 @@ begin
|
|
70
71
|
puts response.text
|
71
72
|
rescue => e
|
72
73
|
puts "Error: #{e.message}"
|
73
|
-
puts "Make sure
|
74
|
+
puts "Make sure the path './examples/ruby.png' is correct."
|
74
75
|
end
|
75
76
|
|
76
77
|
puts "\n============================================================"
|
@@ -79,19 +80,19 @@ puts "============================================================"
|
|
79
80
|
|
80
81
|
begin
|
81
82
|
# Read image directly into bytes
|
82
|
-
image_bytes = File.binread("
|
83
|
+
image_bytes = File.binread("./examples/ruby.png") # Updated path
|
83
84
|
|
84
85
|
# Generate content with raw image bytes
|
85
86
|
response = Geminize.generate_text_multimodal(
|
86
87
|
"Analyze this image:",
|
87
|
-
[{source_type: "bytes", data: image_bytes, mime_type: "image/
|
88
|
+
[{source_type: "bytes", data: image_bytes, mime_type: "image/png"}] # Updated MIME type
|
88
89
|
)
|
89
90
|
|
90
91
|
puts "Response for raw bytes input:"
|
91
92
|
puts response.text
|
92
93
|
rescue => e
|
93
94
|
puts "Error: #{e.message}"
|
94
|
-
puts "Make sure
|
95
|
+
puts "Make sure the path './examples/ruby.png' is correct."
|
95
96
|
end
|
96
97
|
|
97
98
|
puts "\n============================================================"
|
@@ -111,16 +112,22 @@ begin
|
|
111
112
|
)
|
112
113
|
|
113
114
|
# Add multiple images using different methods
|
114
|
-
request.add_image_from_file("
|
115
|
-
request.add_image_from_url("https://
|
115
|
+
request.add_image_from_file("./examples/ruby.png") # Updated path
|
116
|
+
request.add_image_from_url("https://miro.medium.com/v2/resize:fit:720/format:webp/1*zkA1cWgJDlMUxI5TRcIHdQ.jpeg") # Updated URL
|
116
117
|
|
117
118
|
# Generate the response
|
118
119
|
response = generator.generate(request)
|
119
120
|
|
120
121
|
puts "Response using ContentRequest directly:"
|
121
122
|
puts response.text
|
122
|
-
|
123
|
+
|
124
|
+
# Check if usage data is available before accessing it
|
125
|
+
if response.usage && response.usage.total_tokens
|
126
|
+
puts "\nUsed #{response.usage.total_tokens} tokens total"
|
127
|
+
else
|
128
|
+
puts "\nUsage data not available in the response."
|
129
|
+
end
|
123
130
|
rescue => e
|
124
131
|
puts "Error: #{e.message}"
|
125
|
-
puts "Make sure
|
132
|
+
puts "Make sure paths and URLs are valid."
|
126
133
|
end
|
data/examples/ruby.png
ADDED
Binary file
|
data/geminize-0.1.0.gem
ADDED
Binary file
|
@@ -211,30 +211,31 @@ module Geminize
|
|
211
211
|
# Convert the request to a hash suitable for the API
|
212
212
|
# @return [Hash] The request as a hash
|
213
213
|
def to_hash
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
else
|
224
|
-
# Keep backward compatibility for text-only requests
|
225
|
-
{
|
226
|
-
contents: [
|
227
|
-
{
|
228
|
-
parts: [
|
229
|
-
{
|
230
|
-
text: @prompt
|
231
|
-
}
|
232
|
-
]
|
214
|
+
# Map content_parts to the structure the API expects
|
215
|
+
api_parts = @content_parts.map do |part|
|
216
|
+
if part[:type] == "text"
|
217
|
+
{ text: part[:text] }
|
218
|
+
elsif part[:type] == "image"
|
219
|
+
{
|
220
|
+
inlineData: {
|
221
|
+
mimeType: part[:mime_type],
|
222
|
+
data: part[:data]
|
233
223
|
}
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
224
|
+
}
|
225
|
+
else
|
226
|
+
# Handle potential future types or raise error
|
227
|
+
nil # Or raise an error for unknown part types
|
228
|
+
end
|
229
|
+
end.compact # Remove any nil parts from unknown types
|
230
|
+
|
231
|
+
request = {
|
232
|
+
contents: [
|
233
|
+
{
|
234
|
+
parts: api_parts # Use the correctly formatted parts
|
235
|
+
}
|
236
|
+
],
|
237
|
+
generationConfig: generation_config
|
238
|
+
}.compact
|
238
239
|
|
239
240
|
# Add system_instruction if provided
|
240
241
|
if @system_instruction
|
data/lib/geminize/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geminize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nhat Long Nguyen
|
8
8
|
bindir: exe
|
9
9
|
cert_chain: []
|
10
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
11
|
dependencies:
|
12
12
|
- !ruby/object:Gem::Dependency
|
13
13
|
name: faraday
|
@@ -149,7 +149,9 @@ files:
|
|
149
149
|
- examples/rails_chat/app/views/chat/index.html.erb
|
150
150
|
- examples/rails_chat/config/routes.rb
|
151
151
|
- examples/rails_initializer.rb
|
152
|
+
- examples/ruby.png
|
152
153
|
- examples/system_instructions.rb
|
154
|
+
- geminize-0.1.0.gem
|
153
155
|
- lib/geminize.rb
|
154
156
|
- lib/geminize/chat.rb
|
155
157
|
- lib/geminize/client.rb
|
@@ -212,7 +214,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
212
214
|
- !ruby/object:Gem::Version
|
213
215
|
version: '0'
|
214
216
|
requirements: []
|
215
|
-
rubygems_version: 3.6.
|
217
|
+
rubygems_version: 3.6.8
|
216
218
|
specification_version: 4
|
217
219
|
summary: Ruby interface for Google's Gemini AI API
|
218
220
|
test_files: []
|