davsclaus opened a new pull request, #29034: URL: https://github.com/apache/camel/pull/29034
Fixes [CAMEL-26209](https://issues.apache.org/jira/browse/CAMEL-26209). ### 1. An ImagePrompt body ignored the endpoint options and headers **What was wrong:** `SpringAiImageProducer` sent an `ImagePrompt` body as is. `buildImageOptions` ran only for a text body, so `n`, `width`, `height`, `model`, `responseFormat` and `style` from the endpoint or the headers did not apply. Even `new ImagePrompt("text")`, which has empty options, got none of them. **What changed:** for an `ImagePrompt` body, the producer now builds the options in this order: the prompt's own value, then the header, then the endpoint option. The prompt's instructions (text and weight) are kept. This applies when the prompt has no options or generic options (`new ImagePrompt(text)`, `ImageOptionsBuilder`). Provider options such as `OpenAiImageOptions` are still sent as is: `ImageOptions` has only getters, so a merged copy would have to be a generic `ImageOptions`. That copy would lose the provider settings, such as the OpenAI `quality` and `user`. ### 2. An Image with only a URL converted to the URL text as bytes **What was wrong:** `SpringAiImageConverter.toBytes` returned `image.getUrl().getBytes()` when the `Image` had no base64 data, and `toInputStream` used it. So `.to("spring-ai-image:gen").to("file:out?fileName=img.png")` wrote the URL text into the `.png`. **What changed:** the `byte[]` and `InputStream` conversions of a URL-only `Image` now fail. The message tells the user to set `responseFormat=b64_json` or to download the URL. The message does not include the URL, because provider URLs are often signed. The conversion to `String` still gives the URL. An `Image` with neither base64 data nor a URL still converts to an empty `byte[]` (unchanged). ### Tests - `SpringAiImageProducerTest` (5 tests, fake `ImageModel`): text body with endpoint options and a header; `ImagePrompt` with empty options; `ImagePrompt` with null options (keeps the message weight); prompt options win over the header and the endpoint; provider options are passed as is. - `SpringAiImageConverterTest` (3 tests): base64 to `byte[]`/`InputStream`/`String`; a URL-only `Image` fails for `byte[]` and `InputStream` and still gives the URL as `String`; a route to `file:` fails and writes no file. - Without the fix, 5 of the 8 tests fail (the 3 `ImagePrompt` merge tests and the 2 URL-only tests). The module builds with `-Psourcecheck`. ### Docs and generated files - The component doc has a new section, "With an ImagePrompt body". The converter table and the "Saving Images to Files" note are updated. - The endpoint `@BodyTypes` text is updated. The component JSON is regenerated and copied into `camel-catalog`, together with the doc. No option or header changed, so the endpoint DSL is not regenerated. - Upgrade guide 4.24: a new `camel-spring-ai-image` entry for both behaviour changes. ### Not changed - Provider options in an `ImagePrompt` are not merged (see above). _Claude Code on behalf of Claus Ibsen (davsclaus)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
