Skip to content

Commit

Permalink
feat(doc handle): doc handling for bedrock
Browse files Browse the repository at this point in the history
  • Loading branch information
DenovVasil committed Dec 18, 2024
1 parent d224f09 commit 27f5854
Show file tree
Hide file tree
Showing 28 changed files with 932 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ camunda.client.zeebe.gateway-url=http://localhost:26500
camunda.client.zeebe.defaults.max-jobs-active=32
camunda.client.zeebe.defaults.worker-threads=10
camunda.client.zeebe.defaults.stream-enabled=true
camunda.client.zeebe.rest-address=http://localhost:8080

camunda.client.mode=self-managed

# Config for use with docker-compose.yml
camunda.client.zeebe.rest-address=http://localhost:8080
camunda.client.zeebe.rest-address=http://localhost:8088
camunda.client.auth.client-id=connectors
camunda.client.auth.client-secret=XALaRPl5qwTEItdwCMiPS62nVpKs7dL7
camunda.client.auth.oidc-type=keycloak
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"name" : "AWS BedRock Outbound Connector",
"id" : "io.camunda.connectors.aws.bedrock.v1",
"description" : "Execute bedrock requests",
"metadata" : {
"keywords" : [ ]
},
"documentationRef" : "https://docs.camunda.io/docs/",
"version" : 1,
"category" : {
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
Expand Up @@ -3,6 +3,9 @@
"name" : "Hybrid AWS BedRock Outbound Connector",
"id" : "io.camunda.connectors.aws.bedrock.v1-hybrid",
"description" : "Execute bedrock requests",
"metadata" : {
"keywords" : [ ]
},
"documentationRef" : "https://docs.camunda.io/docs/",
"version" : 1,
"category" : {
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 @@ -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

0 comments on commit 27f5854

Please sign in to comment.