[ 
https://issues.apache.org/jira/browse/CAMEL-26521?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18146048#comment-18146048
 ] 

Karol Krawczyk commented on CAMEL-26521:
----------------------------------------

I would like to take this. The premise holds on main (8e904a3bb0f7): 
{{AbstractWatsonxAiHandler.getInput}}, {{getInputs}} and {{getMessages}} fall 
back to {{in.getBody(String.class)}}, and for a Map or a POJO the only 
conversion is {{ToStringTypeConverter}}, so the model is asked about a map 
written in Java notation. That is the ten operations you list.

PR: https://github.com/apache/camel/pull/30256

h3. How a body is judged

Instead of a list of accepted types, a body is rejected only when the text the 
converter gives is the {{toString()}} of the object: {{BodyFacts.kindOf(body) 
!= PAYLOAD && text.equals(body.toString())}}. {{ToStringTypeConverter}} is 
registered with {{canPromote = false}} and returns exactly 
{{value.toString()}}, so that equality is the signal that nothing else read the 
body as text.

The reason for not writing an accept list is CAMEL-26553: in 
camel-spring-ai-embeddings and camel-langchain4j-embeddings such a list rejects 
a {{char[]}}, a Netty {{ByteBuf}} and a custom type with its own converter to 
{{String}}, which worked before. 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 registry instead would not work: {{putConverter}} 
caches the fallback for the exact pair before the {{canPromote}} check, so 
after the first Map body {{lookup(String.class, HashMap.class)}} reports a 
converter.

h3. Beyond your list, both your call

* 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. I 
routed those nine reads through the same check, so the sentence is true for the 
whole description. Say the word and I will 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. Worth its own ticket?

h3. In the PR

* the check in {{AbstractWatsonxAiHandler}}, used by the three text reads and 
the nine path and id reads
* 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; a 
{{char[]}} and a {{ByteBuffer}} body still reach the model as their text. All 
ten failing cases fail with the check reverted, so they bind.
* the catalog {{bodyTypes}} description, the component page, the catalog 
copies, and an upgrade-guide entry for 4.24

Could you assign it to me?

_Reported by Claude Code on behalf of Karol Krawczyk_

> camel-ibm-watsonx-ai - the text operations send a Map or a POJO body to the 
> model as its toString()
> ---------------------------------------------------------------------------------------------------
>
>                 Key: CAMEL-26521
>                 URL: https://issues.apache.org/jira/browse/CAMEL-26521
>             Project: Camel
>          Issue Type: Improvement
>          Components: camel-ai
>            Reporter: Andrea Cosentino
>            Priority: Minor
>
> Follow-up of CAMEL-26222 ([PR 
> #28971|https://github.com/apache/camel/pull/28971]).
> The operations that read the message body as text (textGeneration, 
> textGenerationStreaming, chat, chatStreaming, deploymentGenerate, 
> deploymentChat, tokenize, detect, embedding, rerank) convert a body that is 
> not text with {{getBody(String.class)}}, so a Map or a POJO reaches the model 
> as its {{toString()}}, for example {{\{a=b\}}}. The catalog body types 
> document this.
> Proposed: fail with a clear {{IllegalArgumentException}} for a Map or a POJO 
> body, saying to marshal it first (for example with {{marshal().json()}}) or 
> to give the text. Keep text, bytes, streams and files, the List bodies of 
> chat, embedding and rerank, and a {{ChatMessage}} body for chat as they are. 
> This needs an upgrade-guide entry, since such a body now fails where it used 
> to be sent.
> _Claude Code on behalf of Andrea Cosentino (oscerd)_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to