Skip to content

Commit 213e601

Browse files
authored
Support gpt-image-1 (#201)
Resolves #200 Seems pretty simple to me. Borrowed the model passing idea from #152
1 parent 12942b7 commit 213e601

File tree

5 files changed

+96
-5
lines changed

5 files changed

+96
-5
lines changed

lib/ruby_llm/provider.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def embed(text, model:, connection:, dimensions:)
4040
def paint(prompt, model:, size:, connection:)
4141
payload = render_image_payload(prompt, model:, size:)
4242
response = connection.post images_url, payload
43-
parse_image_response response
43+
parse_image_response(response, model:)
4444
end
4545

4646
def configured?(config = nil)

lib/ruby_llm/providers/gemini/images.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def render_image_payload(prompt, model:, size:)
2424
}
2525
end
2626

27-
def parse_image_response(response)
27+
def parse_image_response(response, model:)
2828
data = response.body
2929
image_data = data['predictions']&.first
3030

@@ -38,7 +38,8 @@ def parse_image_response(response)
3838

3939
Image.new(
4040
data: base64_data,
41-
mime_type: mime_type
41+
mime_type: mime_type,
42+
model_id: model
4243
)
4344
end
4445
end

lib/ruby_llm/providers/openai/images.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,16 @@ def render_image_payload(prompt, model:, size:)
2020
}
2121
end
2222

23-
def parse_image_response(response)
23+
def parse_image_response(response, model:)
2424
data = response.body
2525
image_data = data['data'].first
2626

2727
Image.new(
2828
url: image_data['url'],
2929
mime_type: 'image/png', # DALL-E typically returns PNGs
3030
revised_prompt: image_data['revised_prompt'],
31-
model_id: data['model']
31+
model_id: model,
32+
data: image_data['b64_json']
3233
)
3334
end
3435
end

spec/fixtures/vcr_cassettes/image_basic_functionality_openai_gpt-image-1_can_paint_images.yml

Lines changed: 77 additions & 0 deletions
Large diffs are not rendered by default.

spec/ruby_llm/image_generation_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def save_and_verify_image(image)
3333
expect(image.url).to start_with('https://')
3434
expect(image.mime_type).to include('image')
3535
expect(image.revised_prompt).to include('cat')
36+
expect(image.model_id).to eq('dall-e-3')
3637

3738
save_and_verify_image image
3839
end
@@ -63,5 +64,16 @@ def save_and_verify_image(image)
6364
RubyLLM.paint('a cat', model: 'invalid-model')
6465
end.to raise_error(RubyLLM::ModelNotFoundError)
6566
end
67+
68+
it 'openai/gpt-image-1 can paint images' do # rubocop:disable RSpec/MultipleExpectations,RSpec/ExampleLength
69+
image = RubyLLM.paint('a siamese cat', model: 'gpt-image-1')
70+
71+
expect(image.base64?).to be(true)
72+
expect(image.data).to be_present
73+
expect(image.mime_type).to include('image')
74+
expect(image.model_id).to eq('gpt-image-1')
75+
76+
save_and_verify_image image
77+
end
6678
end
6779
end

0 commit comments

Comments
 (0)