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/04/04 13:23:38 UTC

(camel) branch CAMEL-20562 created (now fdb23dbc4d5)

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

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


      at fdb23dbc4d5 CAMEL-20562 - Camel-AWS-Bedrock: Support Mistral AI models - Mistral 7B Instruct

This branch includes the following new commits:

     new fdb23dbc4d5 CAMEL-20562 - Camel-AWS-Bedrock: Support Mistral AI models - Mistral 7B Instruct

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-20562 - Camel-AWS-Bedrock: Support Mistral AI models - Mistral 7B Instruct

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

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

commit fdb23dbc4d5ce8ed6a8b43ff186cf5b29c497aa9
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Thu Apr 4 15:05:42 2024 +0200

    CAMEL-20562 - Camel-AWS-Bedrock: Support Mistral AI models - Mistral 7B Instruct
    
    Signed-off-by: Andrea Cosentino <an...@gmail.com>
---
 .../component/aws2/bedrock/BedrockModels.java      |  3 ++-
 .../aws2/bedrock/runtime/BedrockProducer.java      | 13 ++++++++++
 .../runtime/integration/BedrockProducerIT.java     | 29 ++++++++++++++++++++++
 3 files changed, 44 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 ecbf2966a9d..c7688b50286 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
@@ -28,7 +28,8 @@ public enum BedrockModels {
     ANTROPHIC_CLAUDE_V2("anthropic.claude-v2"),
     ANTROPHIC_CLAUDE_V2_1("anthropic.claude-v2:1"),
     ANTROPHIC_CLAUDE_V3("anthropic.claude-3-sonnet-20240229-v1:0"),
-    ANTROPHIC_CLAUDE_HAIKU_V3("anthropic.claude-3-haiku-20240307-v1:0");
+    ANTROPHIC_CLAUDE_HAIKU_V3("anthropic.claude-3-haiku-20240307-v1:0"),
+    MISTRAL_7B_INSTRUCT("mistral.mistral-7b-instruct-v0:2");
 
     public final String model;
 
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 98f48abbcd1..8a2a3fffdd0 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
@@ -256,6 +256,13 @@ public class BedrockProducer extends DefaultProducer {
                     throw new RuntimeException(e);
                 }
             }
+            case "mistral.mistral-7b-instruct-v0:2" -> {
+                try {
+                    setMistralText(result, message);
+                } catch (JsonProcessingException e) {
+                    throw new RuntimeException(e);
+                }
+            }
             default -> throw new IllegalStateException("Unexpected value: " + getConfiguration().getModelId());
         }
     }
@@ -282,6 +289,12 @@ public class BedrockProducer extends DefaultProducer {
         message.setBody(jsonString);
     }
 
+    private void setMistralText(InvokeModelResponse result, Message message) throws JsonProcessingException {
+        ObjectMapper mapper = new ObjectMapper();
+        JsonNode jsonString = mapper.readTree(result.body().asUtf8String());
+        message.setBody(jsonString);
+    }
+
     public static Message getMessageForResponse(final Exchange exchange) {
         return exchange.getMessage();
     }
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 05f720a0a60..52111a22f97 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
@@ -374,6 +374,29 @@ class BedrockProducerIT extends CamelTestSupport {
         MockEndpoint.assertIsSatisfied(context);
     }
 
+    @Test
+    public void testInvokeMistral7BInstructModel() throws InterruptedException {
+
+        result.expectedMessageCount(1);
+        final Exchange result = template.send("direct:send_mistral_7b_instruct_model", exchange -> {
+            ObjectMapper mapper = new ObjectMapper();
+            ObjectNode rootNode = mapper.createObjectNode();
+            rootNode.putIfAbsent("prompt",
+                    new TextNode("\"<s>[INST] Can you tell the history of Mayflower? [/INST]\\\""));
+
+            rootNode.putIfAbsent("max_tokens", new IntNode(300));
+            rootNode.putIfAbsent("temperature", new DoubleNode(0.5));
+            rootNode.putIfAbsent("top_p", new DoubleNode(0.9));
+            rootNode.putIfAbsent("top_k", new IntNode(50));
+
+            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() {
@@ -447,6 +470,12 @@ class BedrockProducerIT extends CamelTestSupport {
                             + BedrockModels.ANTROPHIC_CLAUDE_HAIKU_V3.model)
                         .log("Completions: ${body}")
                         .to(result);
+
+                from("direct:send_mistral_7b_instruct_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.MISTRAL_7B_INSTRUCT.model)
+                        .log("Completions: ${body}")
+                        .to(result);
             }
         };
     }