Skip to content
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
33 changes: 33 additions & 0 deletions packages/pieces/community/aws-bedrock/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"extends": [
"../../../../.eslintrc.base.json"
],
"ignorePatterns": [
"!**/*"
],
"overrides": [
{
"files": [
"*.ts",
"*.tsx",
"*.js",
"*.jsx"
],
"rules": {}
},
{
"files": [
"*.ts",
"*.tsx"
],
"rules": {}
},
{
"files": [
"*.js",
"*.jsx"
],
"rules": {}
}
]
}
7 changes: 7 additions & 0 deletions packages/pieces/community/aws-bedrock/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pieces-aws-bedrock

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build pieces-aws-bedrock` to build the library.
216 changes: 216 additions & 0 deletions packages/pieces/community/aws-bedrock/bun.lock

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions packages/pieces/community/aws-bedrock/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@activepieces/piece-aws-bedrock",
"version": "0.0.1",
"type": "commonjs",
"main": "./src/index.js",
"types": "./src/index.d.ts",
"dependencies": {
"@aws-sdk/client-bedrock": "^3.987.0",
"@aws-sdk/client-bedrock-runtime": "^3.987.0",
"tslib": "^2.3.0"
}
}
66 changes: 66 additions & 0 deletions packages/pieces/community/aws-bedrock/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"name": "pieces-aws-bedrock",
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/pieces/community/aws-bedrock/src",
"projectType": "library",
"release": {
"version": {
"manifestRootsToUpdate": [
"dist/{projectRoot}"
],
"currentVersionResolver": "git-tag",
"fallbackCurrentVersionResolver": "disk"
}
},
"tags": [],
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": [
"{options.outputPath}"
],
"options": {
"outputPath": "dist/packages/pieces/community/aws-bedrock",
"tsConfig": "packages/pieces/community/aws-bedrock/tsconfig.lib.json",
"packageJson": "packages/pieces/community/aws-bedrock/package.json",
"main": "packages/pieces/community/aws-bedrock/src/index.ts",
"assets": [
"packages/pieces/community/aws-bedrock/*.md",
{
"input": "packages/pieces/community/aws-bedrock/src/i18n",
"output": "./src/i18n",
"glob": "**/!(i18n.json)"
}
],
"buildableProjectDepsInPackageJsonType": "dependencies",
"updateBuildableProjectDepsInPackageJson": true,
"clean": false
},
"dependsOn": [
"prebuild",
"^build"
]
},
"nx-release-publish": {
"options": {
"packageRoot": "dist/{projectRoot}"
}
},
"prebuild": {
"dependsOn": [
"^build"
],
"executor": "nx:run-commands",
"options": {
"cwd": "packages/pieces/community/aws-bedrock",
"command": "bun install --no-save --silent"
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": [
"{options.outputFile}"
]
}
}
}
115 changes: 115 additions & 0 deletions packages/pieces/community/aws-bedrock/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import {
PieceAuth,
Property,
createPiece,
} from '@activepieces/pieces-framework';
import { PieceCategory } from '@activepieces/shared';
import { ListFoundationModelsCommand } from '@aws-sdk/client-bedrock';
import { sendPrompt } from './lib/actions/send-prompt';
import { generateContentFromImage } from './lib/actions/generate-content-from-image';
import { generateImage } from './lib/actions/generate-image';
import { generateEmbeddings } from './lib/actions/generate-embeddings';
import { createBedrockClient } from './lib/common';

export const awsBedrockAuth = PieceAuth.CustomAuth({
description: 'AWS Bedrock authentication using Access Key and Secret Key.',
props: {
accessKeyId: Property.ShortText({
displayName: 'Access Key ID',
required: true,
}),
secretAccessKey: PieceAuth.SecretText({
displayName: 'Secret Access Key',
required: true,
}),
region: Property.StaticDropdown({
displayName: 'Region',
required: true,
options: {
options: [
{ label: 'US East (N. Virginia) [us-east-1]', value: 'us-east-1' },
{ label: 'US East (Ohio) [us-east-2]', value: 'us-east-2' },
{ label: 'US West (Oregon) [us-west-2]', value: 'us-west-2' },
{
label: 'Asia Pacific (Hyderabad) [ap-south-2]',
value: 'ap-south-2',
},
{
label: 'Asia Pacific (Mumbai) [ap-south-1]',
value: 'ap-south-1',
},
{
label: 'Asia Pacific (Osaka) [ap-northeast-3]',
value: 'ap-northeast-3',
},
{
label: 'Asia Pacific (Seoul) [ap-northeast-2]',
value: 'ap-northeast-2',
},
{
label: 'Asia Pacific (Singapore) [ap-southeast-1]',
value: 'ap-southeast-1',
},
{
label: 'Asia Pacific (Sydney) [ap-southeast-2]',
value: 'ap-southeast-2',
},
{
label: 'Asia Pacific (Tokyo) [ap-northeast-1]',
value: 'ap-northeast-1',
},
{
label: 'Canada (Central) [ca-central-1]',
value: 'ca-central-1',
},
{
label: 'Europe (Frankfurt) [eu-central-1]',
value: 'eu-central-1',
},
{ label: 'Europe (Ireland) [eu-west-1]', value: 'eu-west-1' },
{ label: 'Europe (London) [eu-west-2]', value: 'eu-west-2' },
{ label: 'Europe (Milan) [eu-south-1]', value: 'eu-south-1' },
{ label: 'Europe (Paris) [eu-west-3]', value: 'eu-west-3' },
{ label: 'Europe (Spain) [eu-south-2]', value: 'eu-south-2' },
{
label: 'Europe (Stockholm) [eu-north-1]',
value: 'eu-north-1',
},
{
label: 'Europe (Zurich) [eu-central-2]',
value: 'eu-central-2',
},
{
label: 'South America (São Paulo) [sa-east-1]',
value: 'sa-east-1',
},
],
},
}),
},
validate: async ({ auth }) => {
try {
const client = createBedrockClient(auth);
await client.send(new ListFoundationModelsCommand({}));
return { valid: true };
} catch (e) {
return {
valid: false,
error: (e as Error)?.message,
};
}
},
required: true,
});

export const awsBedrock = createPiece({
displayName: 'AWS Bedrock',
description: 'Build generative AI applications with foundation models',
auth: awsBedrockAuth,
minimumSupportedRelease: '0.36.1',
logoUrl: 'https://cdn.activepieces.com/pieces/aws-bedrock.png',
categories: [PieceCategory.ARTIFICIAL_INTELLIGENCE],
authors: ["onyedikachi-david"],
actions: [sendPrompt, generateContentFromImage, generateImage, generateEmbeddings],
triggers: [],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
ConverseCommand,
ConversationRole,
ImageFormat,
} from '@aws-sdk/client-bedrock-runtime';
import { ModelModality } from '@aws-sdk/client-bedrock';
import { awsBedrockAuth } from '../../index';
import {
createBedrockRuntimeClient,
getBedrockModelOptions,
formatBedrockError,
extractConverseTextResponse,
} from '../common';

const EXTENSION_TO_FORMAT: Record<string, ImageFormat> = {
png: ImageFormat.PNG,
jpg: ImageFormat.JPEG,
jpeg: ImageFormat.JPEG,
gif: ImageFormat.GIF,
webp: ImageFormat.WEBP,
};

export const generateContentFromImage = createAction({
auth: awsBedrockAuth,
name: 'generate_content_from_image',
displayName: 'Generate Content from Image',
description: 'Ask a Bedrock model a question about an image.',
props: {
model: Property.Dropdown({
displayName: 'Model',
required: true,
auth: awsBedrockAuth,
description: 'The foundation model to use. Must support image input.',
refreshers: [],
options: async ({ auth }) => {
if (!auth) {
return {
disabled: true,
placeholder: 'Connect your AWS account first',
options: [],
};
}
return getBedrockModelOptions(auth.props, {
useInferenceProfiles: true,
inputModality: ModelModality.IMAGE,
});
},
}),
image: Property.File({
displayName: 'Image',
required: true,
description: 'The image to analyze (PNG, JPEG, GIF, or WebP).',
}),
prompt: Property.LongText({
displayName: 'Prompt',
required: true,
description: 'What do you want the model to tell you about the image?',
}),
systemPrompt: Property.LongText({
displayName: 'System Prompt',
required: false,
description: 'Instructions that guide the model behavior.',
}),
temperature: Property.Number({
displayName: 'Temperature',
required: false,
description:
'Controls randomness. Lower values produce more deterministic output.',
defaultValue: 0.7,
}),
maxTokens: Property.Number({
displayName: 'Maximum Tokens',
required: false,
description: 'The maximum number of tokens to generate.',
defaultValue: 2048,
}),
},
async run({ auth, propsValue }) {
const client = createBedrockRuntimeClient(auth.props);
const { model, image, prompt, systemPrompt, temperature, maxTokens } =
propsValue;

const ext = (image.extension ?? 'png').toLowerCase();
const format = EXTENSION_TO_FORMAT[ext];
if (!format) {
throw new Error(
`Unsupported image format "${ext}". Supported: png, jpeg, gif, webp.`
);
}

const imageBytes = Buffer.from(image.base64, 'base64');

try {
const response = await client.send(
new ConverseCommand({
modelId: model,
messages: [
{
role: ConversationRole.USER,
content: [
{
image: {
format,
source: { bytes: imageBytes },
},
},
{ text: prompt },
],
},
],
...(systemPrompt ? { system: [{ text: systemPrompt }] } : {}),
inferenceConfig: {
temperature: temperature ?? undefined,
maxTokens: maxTokens ?? undefined,
},
})
);

return extractConverseTextResponse(response);
} catch (error) {
throw new Error(formatBedrockError(error));
}
},
});
Loading
Loading