Claus Ibsen created CAMEL-27177:
-----------------------------------
Summary: camel-aws-bedrock - converse and converseStream ignore a
text body as prompt
Key: CAMEL-27177
URL: https://issues.apache.org/jira/browse/CAMEL-27177
Project: Camel
Issue Type: Improvement
Components: camel-aws2
Reporter: Claus Ibsen
h3. Problem
The {{converse}} and {{converseStream}} operations of {{aws-bedrock}} read the
conversation only from the {{CamelAwsBedrockConverseMessages}} header, which
must be a {{List}} of AWS SDK
{{software.amazon.awssdk.services.bedrockruntime.model.Message}} objects. With
{{pojoRequest=true}} the body must be a {{ConverseRequest}}. The message body
is never used, although the code comment says "Get messages from header or
body". So a route without Java code (YAML/XML DSL, a Kamelet) cannot call
{{converse}} at all, and with it neither the guardrail endpoint options
({{guardrailIdentifier}}, {{guardrailVersion}}, {{guardrailTrace}}), which are
applied only to {{converse}}, {{converseStream}} and {{applyGuardrail}}.
The Kamelet {{aws-bedrock-text-sink}} cannot offer {{operation: converse}} (the
same prompt for every model, with a guardrail) because of this.
h3. How to reproduce
{code}
- route:
from:
uri: timer:t?repeatCount=1
steps:
- setBody:
constant: "What is Apache Camel?"
- to:
aws-bedrock:label?operation=converse&modelId=anthropic.claude-3-haiku-20240307-v1:0®ion=us-east-1&guardrailIdentifier=abc123&guardrailVersion=1
{code}
Every message fails before any request is sent:
{noformat}
java.lang.IllegalArgumentException: Converse operation requires messages in
header CamelAwsBedrockConverseMessages
{noformat}
h3. Where
*
{{components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockProducer.java}},
{{converse(...)}} and {{converseStream(...)}}: the {{else}} branch throws when
the header is empty.
* {{applyGuardrail(...)}} in the same class reads its content only from
{{CamelAwsBedrockGuardrailContent}} in the same way.
* The body description in {{BedrockEndpoint.java}} ({{@BodyType}}) says these
operations "take their input from headers".
h3. Suggested change
When {{CamelAwsBedrockConverseMessages}} is not set and the body is not empty,
use the body as text as one user message:
{code:java}
String text = exchange.getMessage().getBody(String.class);
builder.messages(Message.builder()
.role(ConversationRole.USER)
.content(ContentBlock.fromText(text))
.build());
{code}
The same for {{converseStream}}, and optionally for {{applyGuardrail}} (one
{{GuardrailContentBlock}} with the body text). The header keeps precedence, so
existing routes are unchanged. Update the {{@BodyType}} description and the
docs, and add a test with a text body.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)