You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Not all models support size customization. Check the provider's documentation or the [Available Models Guide]({% link _reference/available-models.md %}) for supported sizes.
123
124
{: .note }
124
125
126
+
## Using model hosting platforms
127
+
128
+
Platforms like Replicate host a large collection of models with different capabilities and parameters. Due to the variety of models available, you should be aware of the parameters supported by the model you're using. This information is available in the platform's documentation.
129
+
130
+
For example, Imagen 4 Ultra supports `aspect_ratio` as a parameter when used [via Replicate](https://replicate.com/google/imagen-4-ultra). Since it's optional, you can omit it. But if you'd like to specify a value, you just need to add it to your paint call.
131
+
132
+
```ruby
133
+
image =RubyLLM.paint(
134
+
"A photorealistic image of a red panda coding Ruby on a laptop",
135
+
model:"google/imagen-4-ultra",
136
+
provider::replicate,
137
+
aspect_ratio:"16:9"
138
+
)
139
+
```
140
+
141
+
> When switching between different models, you'll typically need to change the parameters as well, since different models support different parameter sets. Always check the model's documentation for the specific parameters it accepts.
142
+
{: .note }
143
+
125
144
## Working with Generated Images
126
145
127
-
The `RubyLLM::Image` object provides access to the generated image data and metadata.
146
+
When models return the image immediately, the `RubyLLM::Image` object provides access to the generated image data and metadata.
147
+
148
+
Some models generate images asynchronously. In this case, you will receive a `RubyLLM::DeferredImage` object instead. You can still access the image data, but you will either need to wait for the image to be generated or fetch it by other means—typically after being notified via a webhook.
128
149
129
150
### Accessing Image Data
130
151
@@ -133,6 +154,10 @@ The `RubyLLM::Image` object provides access to the generated image data and meta
133
154
*`image.mime_type`: Returns the MIME type (e.g., `"image/png"`, `"image/jpeg"`).
134
155
*`image.base64?`: Returns `true` if the image data is Base64-encoded, `false` otherwise.
135
156
157
+
### Accessing Deferred Image Data
158
+
159
+
*`deferred_image.url`: Returns the URL where you can check whether the image has been generated.
160
+
136
161
### Saving Images Locally
137
162
138
163
The `save` method works regardless of whether the image was delivered via URL or Base64. It fetches the data if necessary and writes it to the specified file path.
@@ -150,9 +175,23 @@ rescue => e
150
175
end
151
176
```
152
177
178
+
For deferred images, the `save` method will write the file and return its path only if the image has been generated. Otherwise, it will return `nil`.
179
+
180
+
The ideal way to handle deferred images is by having the provider notify you via webhook when the image is generated, and then fetching the image outside of RubyLLM. But if you're not able to configure a webhook, another way to handle these is to call the method recursively with a delay until it succeeds or a condition is met. This is equivalent to a "polling" mechanism. Check your provider's documentation for any rate limits that may apply.
181
+
182
+
```ruby
183
+
# Only do this if you're not able to configure a webhook
The `to_blob` method returns the raw binary image data (decoded from Base64 or downloaded from URL). This is useful for integration with other libraries or frameworks.
194
+
The `to_blob` method returns the raw binary image data (decoded from Base64 or downloaded from URL). This is useful for integration with other libraries or frameworks. Deferred images return `nil` if the image has not finished generating.
156
195
157
196
```ruby
158
197
image =RubyLLM.paint("Abstract geometric patterns in pastel colors")
0 commit comments