|
21 | 21 | import org.springframework.ai.model.StreamingModel; |
22 | 22 |
|
23 | 23 | /** |
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. |
27 | 26 | * |
28 | 27 | * <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. |
32 | 30 | * </p> |
33 | | - * <ul> |
34 | | - * <li>Partial images at various stages of completion</li> |
35 | | - * <li>The final complete image</li> |
36 | | - * </ul> |
37 | 31 | * |
38 | 32 | * <p> |
39 | 33 | * Example usage: |
40 | 34 | * </p> |
41 | 35 | * |
42 | 36 | * <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()); |
49 | 49 | * }); |
50 | 50 | * }</pre> |
51 | 51 | * |
52 | 52 | * @author Alexandros Pappas |
53 | 53 | * @since 1.1.0 |
54 | 54 | * @see ImageModel |
55 | | - * @see StreamingModel |
56 | 55 | * @see ImagePrompt |
57 | 56 | * @see ImageResponse |
58 | 57 | */ |
59 | 58 | @FunctionalInterface |
60 | 59 | public interface StreamingImageModel extends StreamingModel<ImagePrompt, ImageResponse> { |
61 | 60 |
|
62 | 61 | /** |
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 |
67 | 65 | */ |
68 | 66 | @Override |
69 | 67 | Flux<ImageResponse> stream(ImagePrompt request); |
|
0 commit comments