This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch CAMEL-20764 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 90405879c55bfe3d8530a2f171db254b63f1c801 Author: Andrea Cosentino <[email protected]> AuthorDate: Tue May 14 09:50:48 2024 +0200 CAMEL-20764 - Camel-AWS-Bedrock: Support Amazon Titan Text G1 Premier model Signed-off-by: Andrea Cosentino <[email protected]> --- .../component/aws2/bedrock/BedrockModels.java | 1 + .../aws2/bedrock/runtime/BedrockProducer.java | 3 +- .../runtime/integration/BedrockProducerIT.java | 33 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockModels.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockModels.java index 7b02f216a2e..fe18daa4415 100644 --- a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockModels.java +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockModels.java @@ -23,6 +23,7 @@ public enum BedrockModels { TITAN_IMAGE_GENERATOR_V1("amazon.titan-image-generator-v1"), TITAN_EMBEDDINGS_G1("amazon.titan-embed-text-v1"), TITAN_MULTIMODAL_EMBEDDINGS_G1("amazon.titan-embed-image-v1"), + TITAN_TEXT_PREMIER_V1("amazon.titan-text-premier-v1:0"), JURASSIC2_ULTRA("ai21.j2-ultra-v1"), JURASSIC2_MID("ai21.j2-mid-v1"), ANTROPHIC_CLAUDE_INSTANT_V1("anthropic.claude-instant-v1"), diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockProducer.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockProducer.java index 8f15f4979ca..811329284be 100644 --- a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockProducer.java +++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/runtime/BedrockProducer.java @@ -234,7 +234,8 @@ public class BedrockProducer extends DefaultProducer { protected void setResponseText(InvokeModelResponse result, Message message) { switch (getConfiguration().getModelId()) { - case "amazon.titan-text-express-v1", "amazon.titan-text-lite-v1" -> setTitanText(result, message); + case "amazon.titan-text-express-v1", "amazon.titan-text-lite-v1", "amazon.titan-text-premier-v1:0" -> + setTitanText(result, message); case "ai21.j2-ultra-v1", "ai21.j2-mid-v1" -> { try { setAi21Text(result, message); diff --git a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/integration/BedrockProducerIT.java b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/integration/BedrockProducerIT.java index 9c5ced46233..a045cc23394 100644 --- a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/integration/BedrockProducerIT.java +++ b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/runtime/integration/BedrockProducerIT.java @@ -461,6 +461,34 @@ class BedrockProducerIT extends CamelTestSupport { MockEndpoint.assertIsSatisfied(context); } + @Test + public void testInvokeTitanPremierModel() throws InterruptedException { + + result.expectedMessageCount(1); + final Exchange result = template.send("direct:send_titan_premier", exchange -> { + ObjectMapper mapper = new ObjectMapper(); + ObjectNode rootNode = mapper.createObjectNode(); + rootNode.putIfAbsent("inputText", + new TextNode( + "User: Generate synthetic data for daily product sales in various categories - include row number, product name, category, date of sale and price. Produce output in JSON format. Count records and ensure there are no more than 5.")); + + ArrayNode stopSequences = mapper.createArrayNode(); + stopSequences.add("User:"); + ObjectNode childNode = mapper.createObjectNode(); + childNode.putIfAbsent("maxTokenCount", new IntNode(1024)); + childNode.putIfAbsent("stopSequences", stopSequences); + childNode.putIfAbsent("temperature", new DoubleNode(0.7)); + childNode.putIfAbsent("topP", new DoubleNode(0.9)); + + rootNode.putIfAbsent("textGenerationConfig", childNode); + exchange.getMessage().setBody(mapper.writer().writeValueAsString(rootNode)); + exchange.getMessage().setHeader(BedrockConstants.MODEL_CONTENT_TYPE, "application/json"); + exchange.getMessage().setHeader(BedrockConstants.MODEL_ACCEPT_CONTENT_TYPE, "application/json"); + }); + + MockEndpoint.assertIsSatisfied(context); + } + @Override protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { @@ -494,6 +522,11 @@ class BedrockProducerIT extends CamelTestSupport { + BedrockModels.TITAN_MULTIMODAL_EMBEDDINGS_G1.model) .to(result); + from("direct:send_titan_premier") + .to("aws-bedrock:label?useDefaultCredentialsProvider=true®ion=us-east-1&operation=invokeTextModel&modelId=" + + BedrockModels.TITAN_TEXT_PREMIER_V1.model) + .to(result); + from("direct:send_jurassic2_model") .to("aws-bedrock:label?accessKey=RAW({{aws.manual.access.key}})&secretKey=RAW({{aws.manual.secret.key}}®ion=us-east-1&operation=invokeTextModel&modelId=" + BedrockModels.JURASSIC2_ULTRA.model)
