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:16:56 UTC

(camel) branch CAMEL-20516 created (now 77129840f39)

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

acosentino pushed a change to branch CAMEL-20516
in repository https://gitbox.apache.org/repos/asf/camel.git


      at 77129840f39 CAMEL-20516 - Camel-AWS-Bedrock: Support AI21 Jurassic2 Mid model

This branch includes the following new commits:

     new 77129840f39 CAMEL-20516 - Camel-AWS-Bedrock: Support AI21 Jurassic2 Mid model

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(camel) 01/01: CAMEL-20516 - Camel-AWS-Bedrock: Support AI21 Jurassic2 Mid model

Posted by ac...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 77129840f39deeaaeabedcb002ad4b620fed54d5
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Wed Mar 6 07:16:22 2024 +0100

    CAMEL-20516 - Camel-AWS-Bedrock: Support AI21 Jurassic2 Mid model
    
    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);
             }
         };