Skip to content

Commit cfae97b

Browse files
committed
update docs
Signed-off-by: Alexandros Pappas <apappascs@gmail.com>
1 parent 4f7d157 commit cfae97b

File tree

3 files changed

+39
-24
lines changed

3 files changed

+39
-24
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/image/openai-image.adoc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,16 @@ For example to override the OpenAI specific options such as quality and the numb
170170
ImageResponse response = openaiImageModel.call(
171171
new ImagePrompt("A light cream colored mini golden doodle",
172172
OpenAiImageOptions.builder()
173-
.quality("hd")
173+
.model("dall-e-2") // dall-e-2 supports generating multiple images
174174
.N(4)
175175
.height(1024)
176176
.width(1024).build())
177177
178178
);
179179
----
180180

181+
NOTE: Only DALL-E 2 supports generating multiple images (n > 1). For DALL-E 3 and GPT-Image models, n must be 1.
182+
181183
TIP: In addition to the model specific https://github.com/spring-projects/spring-ai/blob/main/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiImageOptions.java[OpenAiImageOptions] you can use a portable https://github.com/spring-projects/spring-ai/blob/main/spring-ai-model/src/main/java/org/springframework/ai/image/ImageOptions.java[ImageOptions] instance, created with the https://github.com/spring-projects/spring-ai/blob/main/spring-ai-model/src/main/java/org/springframework/ai/image/ImageOptionsBuilder.java[ImageOptionsBuilder#builder()].
182184

183185
== Streaming Image Generation
@@ -249,7 +251,7 @@ OpenAiImageOptions options = OpenAiImageOptions.builder()
249251
.size("1536x1024")
250252
.quality("high")
251253
.background("transparent")
252-
.outputFormat("png")
254+
.outputFormat("jpeg")
253255
.outputCompression(85)
254256
.build();
255257

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/imageclient.adoc

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ For models that support streaming image generation, Spring AI provides the link:
3434

3535
[source,java]
3636
----
37+
@FunctionalInterface
3738
public interface StreamingImageModel extends StreamingModel<ImagePrompt, ImageResponse> {
3839
3940
Flux<ImageResponse> stream(ImagePrompt prompt);
@@ -43,7 +44,21 @@ public interface StreamingImageModel extends StreamingModel<ImagePrompt, ImageRe
4344

4445
The `StreamingImageModel` interface allows AI models to generate images progressively, emitting partial images as they are being created. This provides a better user experience by showing incremental progress rather than waiting for the final image.
4546

46-
NOTE: Streaming image generation is currently only supported by certain models like OpenAI's GPT-Image models (gpt-image-1 and gpt-image-1-mini). Traditional models like DALL-E do not support streaming.
47+
**Example Usage:**
48+
49+
[source,java]
50+
----
51+
ImageOptions options = OpenAiImageOptions.builder()
52+
.model("gpt-image-1-mini")
53+
.stream(true)
54+
.partialImages(2)
55+
.build();
56+
57+
ImagePrompt prompt = new ImagePrompt("A mountain landscape", options);
58+
Flux<ImageResponse> stream = streamingImageModel.stream(prompt);
59+
----
60+
61+
IMPORTANT: Streaming image generation is currently only supported by OpenAI's GPT-Image models (`gpt-image-1` and `gpt-image-1-mini`).
4762

4863
=== ImagePrompt
4964

spring-ai-model/src/main/java/org/springframework/ai/image/StreamingImageModel.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,47 @@
2121
import org.springframework.ai.model.StreamingModel;
2222

2323
/**
24-
* The StreamingImageModel interface provides a reactive API for invoking image generation
25-
* models with streaming response. This enables progressive image generation where partial
26-
* images are emitted as they become available during the generation process.
24+
* Reactive API for streaming image generation. Emits progressive image updates during
25+
* generation, enabling real-time user feedback.
2726
*
2827
* <p>
29-
* Streaming image generation is particularly useful for providing real-time feedback to
30-
* users during long-running image generation tasks. Depending on the model and
31-
* configuration, the stream may emit:
28+
* The stream emits partial images (if configured) followed by the final complete image.
29+
* Partial images are best-effort and model-dependent.
3230
* </p>
33-
* <ul>
34-
* <li>Partial images at various stages of completion</li>
35-
* <li>The final complete image</li>
36-
* </ul>
3731
*
3832
* <p>
3933
* Example usage:
4034
* </p>
4135
*
4236
* <pre>{@code
43-
* ImagePrompt prompt = new ImagePrompt("A serene mountain landscape");
44-
* Flux<ImageResponse> imageStream = streamingImageModel.stream(prompt);
45-
* imageStream.subscribe(response -> {
46-
* // Process each partial or final image response
47-
* Image image = response.getResult().getOutput();
48-
* // Display or save the image
37+
* ImageOptions options = OpenAiImageOptions.builder()
38+
* .model("gpt-image-1-mini")
39+
* .stream(true)
40+
* .partialImages(2)
41+
* .build();
42+
*
43+
* ImagePrompt prompt = new ImagePrompt("A serene mountain landscape", options);
44+
* Flux<ImageResponse> stream = streamingImageModel.stream(prompt);
45+
*
46+
* stream.subscribe(response -> {
47+
* Image image = response.getResult().getOutput();
48+
* displayImage(image.getB64Json());
4949
* });
5050
* }</pre>
5151
*
5252
* @author Alexandros Pappas
5353
* @since 1.1.0
5454
* @see ImageModel
55-
* @see StreamingModel
5655
* @see ImagePrompt
5756
* @see ImageResponse
5857
*/
5958
@FunctionalInterface
6059
public interface StreamingImageModel extends StreamingModel<ImagePrompt, ImageResponse> {
6160

6261
/**
63-
* Executes streaming image generation for the given prompt.
64-
* @param request the image generation request containing the prompt and options
65-
* @return a reactive stream of image responses, potentially including partial images
66-
* during generation and the final complete image
62+
* Streams image generation responses for the given prompt.
63+
* @param request the image prompt with generation options
64+
* @return reactive stream emitting partial images (if configured) and the final image
6765
*/
6866
@Override
6967
Flux<ImageResponse> stream(ImagePrompt request);

0 commit comments

Comments
 (0)