Skip to content

Commit 32e01ee

Browse files
committed
Imageable -> Blobbable
1 parent 4db888e commit 32e01ee

File tree

5 files changed

+22
-26
lines changed

5 files changed

+22
-26
lines changed

lib/ruby_llm/blobbable.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
module RubyLLM
4+
# Mixin for classes that can be used to save a blob to a file
5+
module Blobbable
6+
def save(path)
7+
if (blob = to_blob)
8+
File.binwrite(File.expand_path(path), blob)
9+
path
10+
end
11+
end
12+
13+
def to_blob
14+
raise NotImplementedError, 'to_blob is not implemented'
15+
end
16+
end
17+
end

lib/ruby_llm/deferred_image.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module RubyLLM
44
# Represents an image that may not yet be fully generated.
55
class DeferredImage
6-
include Imageable
6+
include Blobbable
77

88
attr_reader :provider_instance, :url
99

@@ -12,10 +12,6 @@ def initialize(url:, provider_instance:)
1212
@provider_instance = provider_instance
1313
end
1414

15-
def deferred?
16-
true
17-
end
18-
1915
def to_blob
2016
provider_instance.fetch_image_blob(url)
2117
end

lib/ruby_llm/image.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module RubyLLM
44
# Represents a generated image from an AI model.
55
class Image
6-
include Imageable
6+
include Blobbable
77

88
attr_reader :url, :data, :mime_type, :revised_prompt, :model_id
99

lib/ruby_llm/imageable.rb

Lines changed: 0 additions & 17 deletions
This file was deleted.

spec/ruby_llm/image_generation_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def save_and_verify_deferred_image(image)
7575
it 'google/imagen-4-ultra, an official replicate model, can paint images' do
7676
image = RubyLLM.paint('a siamese cat', model: 'google/imagen-4-ultra', output_format: 'png')
7777

78-
expect(image.deferred?).to be(true)
78+
expect(image).to be_a(RubyLLM::DeferredImage)
7979

8080
save_and_verify_deferred_image image
8181
end
@@ -87,15 +87,15 @@ def save_and_verify_deferred_image(image)
8787
image_input: [ref_img1, ref_img2],
8888
output_format: 'png')
8989

90-
expect(image.deferred?).to be(true)
90+
expect(image).to be_a(RubyLLM::DeferredImage)
9191

9292
save_and_verify_deferred_image image
9393
end
9494

9595
it 'prunaai/hidream-l1-fast, an unofficial replicate model, can paint images' do
9696
image = RubyLLM.paint('a siamese cat', model: 'prunaai/hidream-l1-fast', output_format: 'png')
9797

98-
expect(image.deferred?).to be(true)
98+
expect(image).to be_a(RubyLLM::DeferredImage)
9999

100100
save_and_verify_deferred_image image
101101
end

0 commit comments

Comments
 (0)