[
https://issues.apache.org/jira/browse/CAMEL-27797?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Claus Ibsen updated CAMEL-27797:
--------------------------------
Description:
Found while improving the option descriptions of camel-langchain4j-chat for
CAMEL-23832 (commit
https://github.com/apache/camel/commit/8a5ecaf41ffca0f81f3d680155485d5214951a59,
pull request https://github.com/apache/camel/pull/31137).
These are separate problems of the component; the descriptions change only
documents the current behavior.
h4. 1. CHAT_MULTIPLE_MESSAGES with RAG data replaces the last message of the
body list in place
{{LangChain4jChatProducer.sendListChatMessage}} calls
{{chatMessages.set(lastIndex, ...)}} on the body. An immutable body
({{List.of(...)}}) fails with UnsupportedOperationException, and a conversation
history the caller reuses keeps the augmented message, so the RAG text piles up
on later calls.
Proposed change: copy the list before replacing the item.
h4. 2. CHAT_SINGLE_MESSAGE with RAG data fails for a SystemMessage or a
non-text UserMessage
LangChain4j 1.24.1 {{DefaultContentInjector.createPrompt}} casts to UserMessage
and calls {{singleText()}}, so a SystemMessage body with
CamelLangChain4jChatAugmentedData fails with ClassCastException, and a
UserMessage with image or other contents fails with a RuntimeException.
Proposed change: inject only into a UserMessage with a single text content, as
the multiple-messages path already does for the type.
h4. 3. Token count headers can be null
The token count headers are declared as {{int}} but TokenUsage returns Integer,
which can be null; the header is then set to null.
_Claude Code on behalf of davsclaus_
was:
Found while improving the option descriptions of camel-langchain4j-chat for
CAMEL-23832 (pull request https://github.com/apache/camel/pull/31137).
These are separate problems of the component; the descriptions change only
documents the current behavior.
h4. 1. CHAT_MULTIPLE_MESSAGES with RAG data replaces the last message of the
body list in place
{{LangChain4jChatProducer.sendListChatMessage}} calls
{{chatMessages.set(lastIndex, ...)}} on the body. An immutable body
({{List.of(...)}}) fails with UnsupportedOperationException, and a conversation
history the caller reuses keeps the augmented message, so the RAG text piles up
on later calls.
Proposed change: copy the list before replacing the item.
h4. 2. CHAT_SINGLE_MESSAGE with RAG data fails for a SystemMessage or a
non-text UserMessage
LangChain4j 1.24.1 {{DefaultContentInjector.createPrompt}} casts to UserMessage
and calls {{singleText()}}, so a SystemMessage body with
CamelLangChain4jChatAugmentedData fails with ClassCastException, and a
UserMessage with image or other contents fails with a RuntimeException.
Proposed change: inject only into a UserMessage with a single text content, as
the multiple-messages path already does for the type.
h4. 3. Token count headers can be null
The token count headers are declared as {{int}} but TokenUsage returns Integer,
which can be null; the header is then set to null.
_Claude Code on behalf of davsclaus_
> camel-langchain4j-chat: RAG data changes the caller's message list, and fails
> with a SystemMessage or a multi-content UserMessage
> ---------------------------------------------------------------------------------------------------------------------------------
>
> Key: CAMEL-27797
> URL: https://issues.apache.org/jira/browse/CAMEL-27797
> Project: Camel
> Issue Type: Bug
> Components: camel-langchain4j-chat
> Reporter: Claus Ibsen
> Priority: Minor
> Fix For: 4.25.0
>
>
> Found while improving the option descriptions of camel-langchain4j-chat for
> CAMEL-23832 (commit
> https://github.com/apache/camel/commit/8a5ecaf41ffca0f81f3d680155485d5214951a59,
> pull request https://github.com/apache/camel/pull/31137).
> These are separate problems of the component; the descriptions change only
> documents the current behavior.
> h4. 1. CHAT_MULTIPLE_MESSAGES with RAG data replaces the last message of the
> body list in place
> {{LangChain4jChatProducer.sendListChatMessage}} calls
> {{chatMessages.set(lastIndex, ...)}} on the body. An immutable body
> ({{List.of(...)}}) fails with UnsupportedOperationException, and a
> conversation history the caller reuses keeps the augmented message, so the
> RAG text piles up on later calls.
> Proposed change: copy the list before replacing the item.
> h4. 2. CHAT_SINGLE_MESSAGE with RAG data fails for a SystemMessage or a
> non-text UserMessage
> LangChain4j 1.24.1 {{DefaultContentInjector.createPrompt}} casts to
> UserMessage and calls {{singleText()}}, so a SystemMessage body with
> CamelLangChain4jChatAugmentedData fails with ClassCastException, and a
> UserMessage with image or other contents fails with a RuntimeException.
> Proposed change: inject only into a UserMessage with a single text content,
> as the multiple-messages path already does for the type.
> h4. 3. Token count headers can be null
> The token count headers are declared as {{int}} but TokenUsage returns
> Integer, which can be null; the header is then set to null.
> _Claude Code on behalf of davsclaus_
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)