k-krawczyk opened a new pull request, #30256:
URL: https://github.com/apache/camel/pull/30256

   Fixes [CAMEL-26521](https://issues.apache.org/jira/browse/CAMEL-26521), a 
follow-up of CAMEL-26222 (#28971).
   
   The operations that read the message body as text read it with the type 
converter, so a `Map` or a POJO reached the
   model as its `toString()`. They now fail with an `IllegalArgumentException` 
that says to marshal the body first: the
   prompt of `textGeneration`, `textGenerationStreaming`, `tokenize`, `detect` 
and `deploymentGenerate`, the user message
   of `chat`, `chatStreaming` and `deploymentChat`, and the one text of 
`embedding` and `rerank`.
   
   ### How a body is judged
   
   A body is rejected only when the text the converter gives is the 
`toString()` of the object:
   
   ```java
   BodyFacts.kindOf(body) != BodyTypeRegistry.Kind.PAYLOAD && 
text.equals(body.toString())
   ```
   
   `ToStringTypeConverter` is registered with `canPromote = false` and returns 
exactly `value.toString()`, so that
   equality is the signal that no other converter read the body as text.
   
   There is no list of accepted types on purpose. CAMEL-26553 reports that such 
a list, in camel-spring-ai-embeddings and
   camel-langchain4j-embeddings, rejects a `char[]`, a Netty `ByteBuf` and a 
custom type with its own converter to
   `String`, which worked before it. With the rule above those bodies keep 
working here, and whatever CAMEL-26553 settles
   on does not have to be applied to watsonx again. Asking the type converter 
registry instead does not work:
   `CoreTypeConverterRegistry.putConverter` caches the fallback for the exact 
pair of types before the `canPromote` check,
   so after the first `Map` body `lookup(String.class, HashMap.class)` reports 
a converter.
   
   ### Beyond the ten operations of the ticket
   
   The file path, job id and file name of the extraction and classification 
operations that do not upload read the body
   the same way, and the catalog `bodyTypes` description covers them in the 
same sentence as the prompt. Those nine reads
   go through the same check, so the sentence holds for the whole description. 
Happy to drop them and word the
   description per group instead.
   
   `getInputs` still casts a `List` body to `List<String>` unchecked, so a 
`List` with a `Map` element reaches the SDK,
   where CAMEL-26222 fixed the same thing for chat messages. Left alone, since 
the ticket says to keep the `List` bodies
   as they are.
   
   ### Tests
   
   12 tests in `WatsonxAiMessageBodyTest`, 33 in that class now. A `Map` or a 
POJO body fails for `chat`,
   `chatStreaming`, `deploymentChat`, `embedding`, `rerank`, `textGeneration`, 
`tokenize`, `textExtraction` and
   `textClassificationFetch`, and no request is sent; a `char[]` and a 
`ByteBuffer` body still reach the model as their
   text. All ten failing cases fail with the production check reverted. The 
module is green with `-Psourcecheck`
   (46 unit tests).
   
   ### Docs
   
   The catalog `bodyTypes` description, the component page, the generated 
catalog copies, and an entry in the 4.24
   upgrade guide, since a body that was sent before now fails.
   
   cc @oscerd @davsclaus
   
   _Reported by Claude Code on behalf of Karol Krawczyk_
   


-- 
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]

Reply via email to