ruby_llm 0.1.0.pre43 → 0.1.0.pre44
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/.rspec_status +4 -4
- data/lib/ruby_llm/image.rb +26 -3
- data/lib/ruby_llm/provider.rb +10 -0
- data/lib/ruby_llm/providers/gemini/images.rb +6 -5
- data/lib/ruby_llm/providers/openai/images.rb +1 -0
- data/lib/ruby_llm/version.rb +1 -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: 519b87700f2ba3d5aeb8ea3a87d0881f4ef58f974991647b7af4c9f138cbf3d2
|
4
|
+
data.tar.gz: 553b6441ad59fe5efe6d51374103690101c2cb8d072f91bf2a850d84b4934601
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e52cb96479a0f4443521bf3b5b2e98c882fb1c404e3d1527c74f638137bf56c2cb9442cc6e30ef197157fbdaa7dc189b7f6331a31e6f31ddfa28a926035d6578
|
7
|
+
data.tar.gz: b1d7948851e6c1ffa5257e214f01e6d6efaf64d32d98dcc66ec8f5d6776df232a92b3b26ff1de78889f4195ff27e41dc7375a4b2530dc1b97edc8fd57bb2c835
|
data/.rspec_status
CHANGED
@@ -35,7 +35,7 @@ example_id | status | run_time |
|
|
35
35
|
./spec/ruby_llm/embeddings_spec.rb[1:1:2:1] | passed | 0.65614 seconds |
|
36
36
|
./spec/ruby_llm/embeddings_spec.rb[1:1:2:2] | passed | 2.16 seconds |
|
37
37
|
./spec/ruby_llm/error_handling_spec.rb[1:1] | passed | 0.29366 seconds |
|
38
|
-
./spec/ruby_llm/image_generation_spec.rb[1:1:1] | passed |
|
39
|
-
./spec/ruby_llm/image_generation_spec.rb[1:1:2] | passed |
|
40
|
-
./spec/ruby_llm/image_generation_spec.rb[1:1:3] | passed |
|
41
|
-
./spec/ruby_llm/image_generation_spec.rb[1:1:4] | passed | 0.
|
38
|
+
./spec/ruby_llm/image_generation_spec.rb[1:1:1] | passed | 24.16 seconds |
|
39
|
+
./spec/ruby_llm/image_generation_spec.rb[1:1:2] | passed | 14.81 seconds |
|
40
|
+
./spec/ruby_llm/image_generation_spec.rb[1:1:3] | passed | 9.17 seconds |
|
41
|
+
./spec/ruby_llm/image_generation_spec.rb[1:1:4] | passed | 0.00083 seconds |
|
data/lib/ruby_llm/image.rb
CHANGED
@@ -3,16 +3,39 @@
|
|
3
3
|
module RubyLLM
|
4
4
|
# Represents a generated image from an AI model.
|
5
5
|
# Provides an interface to image generation capabilities
|
6
|
-
# from providers like DALL-E.
|
6
|
+
# from providers like DALL-E and Gemini's Imagen.
|
7
7
|
class Image
|
8
|
-
attr_reader :url, :revised_prompt, :model_id
|
8
|
+
attr_reader :url, :data, :mime_type, :revised_prompt, :model_id
|
9
9
|
|
10
|
-
def initialize(url
|
10
|
+
def initialize(url: nil, data: nil, mime_type: nil, revised_prompt: nil, model_id: nil)
|
11
11
|
@url = url
|
12
|
+
@data = data
|
13
|
+
@mime_type = mime_type
|
12
14
|
@revised_prompt = revised_prompt
|
13
15
|
@model_id = model_id
|
14
16
|
end
|
15
17
|
|
18
|
+
def base64?
|
19
|
+
!@data.nil?
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns the raw binary image data regardless of source
|
23
|
+
def to_blob
|
24
|
+
if base64?
|
25
|
+
Base64.decode64(@data)
|
26
|
+
else
|
27
|
+
# Use Faraday instead of URI.open for better security
|
28
|
+
response = Faraday.get(@url)
|
29
|
+
response.body
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Saves the image to a file path
|
34
|
+
def save(path)
|
35
|
+
File.binwrite(File.expand_path(path), to_blob)
|
36
|
+
path
|
37
|
+
end
|
38
|
+
|
16
39
|
def self.paint(prompt, model: nil, size: '1024x1024')
|
17
40
|
model_id = model || RubyLLM.config.default_image_model
|
18
41
|
Models.find(model_id) # Validate model exists
|
data/lib/ruby_llm/provider.rb
CHANGED
@@ -158,6 +158,16 @@ module RubyLLM
|
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
161
|
+
def parse_data_uri(uri)
|
162
|
+
if uri&.start_with?('data:')
|
163
|
+
match = uri.match(/\Adata:([^;]+);base64,(.+)\z/)
|
164
|
+
return { mime_type: match[1], data: match[2] } if match
|
165
|
+
end
|
166
|
+
|
167
|
+
# If it's not a data URI, return nil
|
168
|
+
nil
|
169
|
+
end
|
170
|
+
|
161
171
|
class << self
|
162
172
|
def extended(base)
|
163
173
|
base.extend(Methods)
|
@@ -37,12 +37,13 @@ module RubyLLM
|
|
37
37
|
raise Error, 'Unexpected response format from Gemini image generation API'
|
38
38
|
end
|
39
39
|
|
40
|
-
#
|
41
|
-
|
40
|
+
# Extract mime type and base64 data
|
41
|
+
mime_type = image_data['mimeType'] || 'image/png'
|
42
|
+
base64_data = image_data['bytesBase64Encoded']
|
43
|
+
|
42
44
|
Image.new(
|
43
|
-
|
44
|
-
|
45
|
-
model_id: ''
|
45
|
+
data: base64_data,
|
46
|
+
mime_type: mime_type
|
46
47
|
)
|
47
48
|
end
|
48
49
|
end
|
data/lib/ruby_llm/version.rb
CHANGED