You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2024/03/06 06:50:08 UTC

(camel) branch main updated: CAMEL-20516 - Camel-AWS-Bedrock: Support AI21 Jurassic2 Mid model (#13386)

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 8455c3a9f3d CAMEL-20516 - Camel-AWS-Bedrock: Support AI21 Jurassic2 Mid model (#13386)
8455c3a9f3d is described below

commit 8455c3a9f3dd2c1ad7c765055208b23576005819
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Mar 6 07:50:02 2024 +0100

    CAMEL-20516 - Camel-AWS-Bedrock: Support AI21 Jurassic2 Mid model (#13386)
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../component/aws2/bedrock/BedrockModels.java      |  3 +-
 .../component/aws2/bedrock/BedrockProducer.java    |  2 +-
 .../bedrock/integration/BedrockProducerIT.java     | 48 ++++++++++++++++++++++
 3 files changed, 51 insertions(+), 2 deletions(-)

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 5d322aa340d..bc16f068e7e 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
@@ -22,7 +22,8 @@ public enum BedrockModels {
     TITAN_TEXT_LITE_V1("amazon.titan-text-lite-v1"),
     TITAN_IMAGE_GENERATOR_V1("amazon.titan-image-generator-v1"),
     TITAN_EMBEDDINGS_G1("amazon.titan-embed-text-v1"),
-    JURASSIC2_ULTRA("ai21.j2-ultra-v1"),;
+    JURASSIC2_ULTRA("ai21.j2-ultra-v1"),
+    JURASSIC2_MID("ai21.j2-mid-v1");
 
     public final String model;
 
diff --git a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockProducer.java b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockProducer.java
index 421e75bf882..3434fea5921 100644
--- a/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockProducer.java
+++ b/components/camel-aws/camel-aws-bedrock/src/main/java/org/apache/camel/component/aws2/bedrock/BedrockProducer.java
@@ -235,7 +235,7 @@ 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 "ai21.j2-ultra-v1" -> {
+            case "ai21.j2-ultra-v1", "ai21.j2-mid-v1" -> {
                 try {
                     setAi21Text(result, message);
                 } catch (JsonProcessingException e) {
diff --git a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/integration/BedrockProducerIT.java b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/integration/BedrockProducerIT.java
index 12debf2fcaa..a071215eb02 100644
--- a/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/integration/BedrockProducerIT.java
+++ b/components/camel-aws/camel-aws-bedrock/src/test/java/org/apache/camel/component/aws2/bedrock/integration/BedrockProducerIT.java
@@ -167,6 +167,45 @@ class BedrockProducerIT extends CamelTestSupport {
             rootNode.putIfAbsent("temperature", new IntNode(0));
             rootNode.putIfAbsent("topP", new IntNode(1));
 
+            ArrayNode stopSequences = mapper.createArrayNode();
+            stopSequences.add("###");
+
+            rootNode.putIfAbsent("stopSequences", stopSequences);
+
+            ObjectNode childNode = mapper.createObjectNode();
+            childNode.putIfAbsent("scale", new IntNode(0));
+
+            rootNode.putIfAbsent("presencePenalty", childNode);
+            rootNode.putIfAbsent("frequencyPenalty", 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);
+    }
+
+    @Test
+    public void testInvokeJurassic2MidModel() throws InterruptedException {
+
+        result.expectedMessageCount(1);
+        final Exchange result = template.send("direct:send_jurassic2_mid_model", exchange -> {
+            ObjectMapper mapper = new ObjectMapper();
+            ObjectNode rootNode = mapper.createObjectNode();
+            rootNode.putIfAbsent("prompt",
+                    new TextNode(
+                            "\"Apple Inc. (NASDAQ:AAPL) Q3 2023 Earnings Conference Call August 3, 2023 5:00 PM ET Operator\\\\nGood day, and welcome to the Apple Q3 Fiscal Year 2023 Earnings Conference Call. Today's call is being recorded. At this time, for opening remarks and introductions, I would like to turn the call over to Saori Casey, Vice President of Finance. Please go ahead.\\\\nSaori Casey\\\\nThank you. Good afternoon, and thank you for joining us. Speaking first today is Ap [...]
+
+            rootNode.putIfAbsent("maxTokens", new IntNode(500));
+            rootNode.putIfAbsent("temperature", new IntNode(0));
+            rootNode.putIfAbsent("topP", new IntNode(1));
+
+            ArrayNode stopSequences = mapper.createArrayNode();
+            stopSequences.add("###");
+
+            rootNode.putIfAbsent("stopSequences", stopSequences);
+
             ObjectNode childNode = mapper.createObjectNode();
             childNode.putIfAbsent("scale", new IntNode(0));
 
@@ -214,6 +253,15 @@ class BedrockProducerIT extends CamelTestSupport {
                             + BedrockModels.JURASSIC2_ULTRA.model)
                         .split(body())
                         .transform().jq(".data.text")
+                        .log("Completions: ${body}")
+                        .to(result);
+
+                from("direct:send_jurassic2_mid_model")
+                        .to("aws-bedrock:label?accessKey=RAW({{aws.manual.access.key}})&secretKey=RAW({{aws.manual.secret.key}}&region=us-east-1&operation=invokeTextModel&modelId="
+                            + BedrockModels.JURASSIC2_MID.model)
+                        .split(body())
+                        .transform().jq(".data.text")
+                        .log("Completions: ${body}")
                         .to(result);
             }
         };