Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(doc handle): documentation handling for bedrock #3751

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably done but just in case: remember the webmodeler pr :)

Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"$schema" : "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
"name" : "AWS BedRock Outbound Connector",
"name" : "AWS Bedrock Outbound Connector",
"id" : "io.camunda.connectors.aws.bedrock.v1",
"description" : "Execute bedrock requests",
"description" : "Invoke models and converse using AWS Bedrock.",
"metadata" : {
"keywords" : [ "invoke model", "run inference", "invokemodel API", "converse API" ]
},
"documentationRef" : "https://docs.camunda.io/docs/",
"version" : 1,
"version" : 2,
"category" : {
"id" : "connectors",
"name" : "Connectors"
Expand Down Expand Up @@ -186,6 +189,23 @@
"type" : "simple"
},
"type" : "String"
}, {
"id" : "data.messagesHistory",
"label" : "Message History",
"description" : "Specify the message history, when previous context is needed",
"optional" : true,
"feel" : "required",
"group" : "converse",
"binding" : {
"name" : "data.messagesHistory",
"type" : "zeebe:input"
},
"condition" : {
"property" : "action",
"equals" : "converse",
"type" : "simple"
},
"type" : "String"
}, {
"id" : "data.modelId1",
"label" : "Model ID",
Expand All @@ -207,7 +227,7 @@
},
"type" : "String"
}, {
"id" : "data.nextMessage",
"id" : "data.newMessage",
"label" : "New Message",
"description" : "Specify the next message",
"optional" : false,
Expand All @@ -217,7 +237,7 @@
"feel" : "optional",
"group" : "converse",
"binding" : {
"name" : "data.nextMessage",
"name" : "data.newMessage",
"type" : "zeebe:input"
},
"condition" : {
Expand All @@ -227,14 +247,13 @@
},
"type" : "String"
}, {
"id" : "data.messages",
"label" : "Message History",
"description" : "Specify the message history, when previous context is needed",
"id" : "data.maxTokens",
"label" : "Max token returned",
"optional" : true,
"feel" : "required",
"feel" : "optional",
"group" : "converse",
"binding" : {
"name" : "data.messages",
"name" : "data.maxTokens",
"type" : "zeebe:input"
},
"condition" : {
Expand All @@ -244,13 +263,13 @@
},
"type" : "String"
}, {
"id" : "data.maxTokens",
"label" : "Max token returned",
"id" : "data.temperature",
"label" : "Temperature",
"optional" : true,
"feel" : "optional",
"group" : "converse",
"binding" : {
"name" : "data.maxTokens",
"name" : "data.temperature",
"type" : "zeebe:input"
},
"condition" : {
Expand All @@ -260,13 +279,13 @@
},
"type" : "String"
}, {
"id" : "data.temperature",
"label" : "Temperature",
"id" : "data.topP",
"label" : "top P",
"optional" : true,
"feel" : "optional",
"group" : "converse",
"binding" : {
"name" : "data.temperature",
"name" : "data.topP",
"type" : "zeebe:input"
},
"condition" : {
Expand All @@ -276,13 +295,13 @@
},
"type" : "String"
}, {
"id" : "data.topP",
"label" : "top P",
"id" : "data.newDocuments",
"label" : "documents",
"optional" : true,
"feel" : "optional",
"feel" : "required",
"group" : "converse",
"binding" : {
"name" : "data.topP",
"name" : "data.newDocuments",
"type" : "zeebe:input"
},
"condition" : {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"$schema" : "https://unpkg.com/@camunda/zeebe-element-templates-json-schema/resources/schema.json",
"name" : "Hybrid AWS BedRock Outbound Connector",
"name" : "Hybrid AWS Bedrock Outbound Connector",
"id" : "io.camunda.connectors.aws.bedrock.v1-hybrid",
"description" : "Execute bedrock requests",
"description" : "Invoke models and converse using AWS Bedrock.",
"metadata" : {
"keywords" : [ "invoke model", "run inference", "invokemodel API", "converse API" ]
},
"documentationRef" : "https://docs.camunda.io/docs/",
"version" : 1,
"version" : 2,
"category" : {
"id" : "connectors",
"name" : "Connectors"
Expand Down Expand Up @@ -191,6 +194,23 @@
"type" : "simple"
},
"type" : "String"
}, {
"id" : "data.messagesHistory",
"label" : "Message History",
"description" : "Specify the message history, when previous context is needed",
"optional" : true,
"feel" : "required",
"group" : "converse",
"binding" : {
"name" : "data.messagesHistory",
"type" : "zeebe:input"
},
"condition" : {
"property" : "action",
"equals" : "converse",
"type" : "simple"
},
"type" : "String"
}, {
"id" : "data.modelId1",
"label" : "Model ID",
Expand All @@ -212,7 +232,7 @@
},
"type" : "String"
}, {
"id" : "data.nextMessage",
"id" : "data.newMessage",
"label" : "New Message",
"description" : "Specify the next message",
"optional" : false,
Expand All @@ -222,7 +242,7 @@
"feel" : "optional",
"group" : "converse",
"binding" : {
"name" : "data.nextMessage",
"name" : "data.newMessage",
"type" : "zeebe:input"
},
"condition" : {
Expand All @@ -232,14 +252,13 @@
},
"type" : "String"
}, {
"id" : "data.messages",
"label" : "Message History",
"description" : "Specify the message history, when previous context is needed",
"id" : "data.maxTokens",
"label" : "Max token returned",
"optional" : true,
"feel" : "required",
"feel" : "optional",
"group" : "converse",
"binding" : {
"name" : "data.messages",
"name" : "data.maxTokens",
"type" : "zeebe:input"
},
"condition" : {
Expand All @@ -249,13 +268,13 @@
},
"type" : "String"
}, {
"id" : "data.maxTokens",
"label" : "Max token returned",
"id" : "data.temperature",
"label" : "Temperature",
"optional" : true,
"feel" : "optional",
"group" : "converse",
"binding" : {
"name" : "data.maxTokens",
"name" : "data.temperature",
"type" : "zeebe:input"
},
"condition" : {
Expand All @@ -265,13 +284,13 @@
},
"type" : "String"
}, {
"id" : "data.temperature",
"label" : "Temperature",
"id" : "data.topP",
"label" : "top P",
"optional" : true,
"feel" : "optional",
"group" : "converse",
"binding" : {
"name" : "data.temperature",
"name" : "data.topP",
"type" : "zeebe:input"
},
"condition" : {
Expand All @@ -281,13 +300,13 @@
},
"type" : "String"
}, {
"id" : "data.topP",
"label" : "top P",
"id" : "data.newDocuments",
"label" : "documents",
"optional" : true,
"feel" : "optional",
"feel" : "required",
"group" : "converse",
"binding" : {
"name" : "data.topP",
"name" : "data.newDocuments",
"type" : "zeebe:input"
},
"condition" : {
Expand Down
6 changes: 6 additions & 0 deletions connectors/aws/aws-bedrock/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
<artifactId>bedrockruntime</artifactId>
<version>${version.software-aws-java-sdk}</version>
</dependency>

<dependency>
<groupId>org.apache.tika</groupId>
<artifactId>tika-core</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@ElementTemplate.Metadata(
keywords = {"invoke model", "run inference", "invokemodel API", "converse API"}),
inputDataClass = BedrockRequest.class,
version = 1,
version = 2,
propertyGroups = {
@ElementTemplate.PropertyGroup(id = "authentication", label = "Authentication"),
@ElementTemplate.PropertyGroup(id = "configuration", label = "Configuration"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import io.camunda.connector.aws.CredentialsProviderSupportV2;
import io.camunda.connector.aws.ObjectMapperSupplier;
import io.camunda.connector.aws.bedrock.model.BedrockRequest;
import io.camunda.connector.aws.bedrock.model.BedrockResponse;
import io.camunda.connector.aws.bedrock.model.RequestData;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient;
Expand All @@ -33,7 +32,7 @@ public static BedrockExecutor create(BedrockRequest bedrockRequest) {
bedrockRequest.getData());
}

public BedrockResponse execute() {
public Object execute() {
return this.requestData.execute(bedrockRuntimeClient, ObjectMapperSupplier.getMapperInstance());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. Licensed under a proprietary license.
* See the License.txt file for more information. You may not use this file
* except in compliance with the proprietary license.
*/
package io.camunda.connector.aws.bedrock.mapper;

import io.camunda.connector.aws.bedrock.model.BedrockContent;
import io.camunda.document.Document;
import java.util.List;
import software.amazon.awssdk.services.bedrockruntime.model.ContentBlock;
import software.amazon.awssdk.services.bedrockruntime.model.DocumentBlock;
import software.amazon.awssdk.services.bedrockruntime.model.ImageBlock;

public class BedrockContentMapper {

private final DocumentMapper documentMapper;

public BedrockContentMapper(DocumentMapper documentMapper) {
this.documentMapper = documentMapper;
}

public BedrockContent messageToBedrockContent(String message) {
return new BedrockContent(message);
}

public List<BedrockContent> documentsToBedrockContent(List<Document> documents) {
if (documents == null) {
return List.of();
}
return documents.stream().map(this::documentToBedrockContent).toList();
}

public BedrockContent documentToBedrockContent(Document document) {
return new BedrockContent(document);
}

/*
* The current implementation supports ContentBlock containing only text.
* */
public List<BedrockContent> mapToBedrockContent(List<ContentBlock> contentBlocks) {
return contentBlocks.stream().map(ContentBlock::text).map(BedrockContent::new).toList();
}

public List<ContentBlock> mapToContentBlocks(List<BedrockContent> contentBlocks) {
return contentBlocks.stream()
.map(
content -> {
String text = content.getText();
if (text != null) {
return mapToContentBlock(text);
}
var document = content.getDocument();
var docBlock = documentMapper.mapToFileBlock(document);
return mapToContentBlock(docBlock);
})
.toList();
}

private ContentBlock mapToContentBlock(Object content) {
return switch (content) {
case String s -> ContentBlock.fromText(s);
case ImageBlock imageBlock -> ContentBlock.fromImage(imageBlock);
default -> ContentBlock.fromDocument((DocumentBlock) content);
};
}

public DocumentMapper getDocumentMapper() {
return documentMapper;
}
}
Loading
Loading