Skip to content

Commit 55a0687

Browse files
committed
Fold image size into model params
1 parent cd04dc4 commit 55a0687

File tree

6 files changed

+10
-14
lines changed

6 files changed

+10
-14
lines changed

docs/_core_features/image-generation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ image_portrait = RubyLLM.paint(
119119
)
120120
```
121121

122-
> Not all models support size customization. If a size is specified for a model that doesn't support it (like Google Imagen), RubyLLM may log a debug message indicating the size parameter is ignored. Check the provider's documentation or the [Available Models Guide]({% link _reference/available-models.md %}) for supported sizes.
122+
> Not all models support size customization. Check the provider's documentation or the [Available Models Guide]({% link _reference/available-models.md %}) for supported sizes.
123123
{: .note }
124124

125125
## Working with Generated Images
@@ -277,4 +277,4 @@ Image generation can take several seconds (typically 5-20 seconds depending on t
277277

278278
* [Chatting with AI Models]({% link _core_features/chat.md %}): Learn about conversational AI.
279279
* [Embeddings]({% link _core_features/embeddings.md %}): Explore text vector representations.
280-
* [Error Handling]({% link _advanced/error-handling.md %}): Master handling API errors.
280+
* [Error Handling]({% link _advanced/error-handling.md %}): Master handling API errors.

lib/ruby_llm/image.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,15 @@ def self.paint(prompt, # rubocop:disable Metrics/ParameterLists
3535
model: nil,
3636
provider: nil,
3737
assume_model_exists: false,
38-
size: '1024x1024',
3938
context: nil,
40-
model_params: {})
39+
**model_params)
4140
config = context&.config || RubyLLM.config
4241
model ||= config.default_image_model
4342
model, provider_instance = Models.resolve(model, provider: provider, assume_exists: assume_model_exists,
4443
config: config)
4544
model_id = model.id
4645

47-
provider_instance.paint(prompt, model: model_id, size:, **model_params)
46+
provider_instance.paint(prompt, model: model_id, **model_params)
4847
end
4948
end
5049
end

lib/ruby_llm/provider.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def moderate(input, model:)
7676
parse_moderation_response(response, model:)
7777
end
7878

79-
def paint(prompt, model:, size:, **params)
80-
payload = render_image_payload(prompt, model:, size:, **params)
79+
def paint(prompt, model:, **params)
80+
payload = render_image_payload(prompt, model:, **params)
8181
response = @connection.post images_url, payload
8282
parse_image_response(response, model:)
8383
end

lib/ruby_llm/providers/gemini/images.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ def images_url
99
"models/#{@model}:predict"
1010
end
1111

12-
def render_image_payload(prompt, model:, size:)
13-
RubyLLM.logger.debug "Ignoring size #{size}. Gemini does not support image size customization."
12+
def render_image_payload(prompt, model:, **)
1413
@model = model
1514
{
1615
instances: [

lib/ruby_llm/providers/openai/images.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ def images_url
1111
'images/generations'
1212
end
1313

14-
def render_image_payload(prompt, model:, size:)
14+
def render_image_payload(prompt, model:, **params)
1515
{
1616
model: model,
1717
prompt: prompt,
1818
n: 1,
19-
size: size
19+
size: params.delete(:size) || '1024x1024'
2020
}
2121
end
2222

lib/ruby_llm/providers/replicate/images.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ def images_url
1515
end
1616
end
1717

18-
def render_image_payload(prompt, model:, size:, **params)
19-
RubyLLM.logger.debug "Use `model_params` for model-dependent sizing instead of size #{size}." if size
20-
18+
def render_image_payload(prompt, model:, **params)
2119
self.model_id = model
2220

2321
{}.tap do |payload|

0 commit comments

Comments
 (0)