Skip to content

Commit 3ecac25

Browse files
feat: implement Claude 3, Claude3.5, Nova Pro, Nova Lite and Mistral model integration with AWS Bedrock (#974)
* feat: Integrate AWS Bedrock with Claude 3.5 Sonnet, Claude 3 Sonnet, and Claude 3.5 Haiku * update Dockerfile for AWS Bedrock configuration * feat: add new Bedrock model 'Mistral' and update Haiku to version 3 * feat: add new bedrock model Nova Lite and Nova Pro * Update README documentation to reflect the latest changes * Add the icon for aws bedrock * add support for serialized AWS Bedrock configuration in api key
1 parent 7e39e92 commit 3ecac25

File tree

11 files changed

+1211
-0
lines changed

11 files changed

+1211
-0
lines changed

.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ XAI_API_KEY=
8383
# You only need this environment variable set if you want to use Perplexity models
8484
PERPLEXITY_API_KEY=
8585

86+
# Get your AWS configuration
87+
# https://console.aws.amazon.com/iam/home
88+
# The JSON should include the following keys:
89+
# - region: The AWS region where Bedrock is available.
90+
# - accessKeyId: Your AWS access key ID.
91+
# - secretAccessKey: Your AWS secret access key.
92+
# - sessionToken (optional): Temporary session token if using an IAM role or temporary credentials.
93+
# Example JSON:
94+
# {"region": "us-east-1", "accessKeyId": "yourAccessKeyId", "secretAccessKey": "yourSecretAccessKey", "sessionToken": "yourSessionToken"}
95+
AWS_BEDROCK_CONFIG=
96+
8697
# Include this environment variable if you want more logging for debugging locally
8798
VITE_LOG_LEVEL=debug
8899

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ARG OLLAMA_API_BASE_URL
2828
ARG XAI_API_KEY
2929
ARG TOGETHER_API_KEY
3030
ARG TOGETHER_API_BASE_URL
31+
ARG AWS_BEDROCK_CONFIG
3132
ARG VITE_LOG_LEVEL=debug
3233
ARG DEFAULT_NUM_CTX
3334

@@ -42,6 +43,7 @@ ENV WRANGLER_SEND_METRICS=false \
4243
XAI_API_KEY=${XAI_API_KEY} \
4344
TOGETHER_API_KEY=${TOGETHER_API_KEY} \
4445
TOGETHER_API_BASE_URL=${TOGETHER_API_BASE_URL} \
46+
AWS_BEDROCK_CONFIG=${AWS_BEDROCK_CONFIG} \
4547
VITE_LOG_LEVEL=${VITE_LOG_LEVEL} \
4648
DEFAULT_NUM_CTX=${DEFAULT_NUM_CTX}
4749

@@ -80,6 +82,7 @@ ENV GROQ_API_KEY=${GROQ_API_KEY} \
8082
XAI_API_KEY=${XAI_API_KEY} \
8183
TOGETHER_API_KEY=${TOGETHER_API_KEY} \
8284
TOGETHER_API_BASE_URL=${TOGETHER_API_BASE_URL} \
85+
AWS_BEDROCK_CONFIG=${AWS_BEDROCK_CONFIG} \
8386
VITE_LOG_LEVEL=${VITE_LOG_LEVEL} \
8487
DEFAULT_NUM_CTX=${DEFAULT_NUM_CTX}
8588

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ bolt.diy was originally started by [Cole Medin](https://www.youtube.com/@ColeMed
7474
- ⬜ Voice prompting
7575
- ⬜ Azure Open AI API Integration
7676
- ✅ Perplexity Integration (@meetpateltech)
77+
- ✅ AWS Bedrock Integration (@kunjabijukchhe)
7778
- ⬜ Vertex AI Integration
7879

7980
## Features

app/components/settings/data/DataTab.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const API_KEY_PROVIDERS = [
2222
'Perplexity',
2323
'Cohere',
2424
'AzureOpenAI',
25+
'AmazonBedrock',
2526
] as const;
2627

2728
interface ApiKeys {
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { BaseProvider } from '~/lib/modules/llm/base-provider';
2+
import type { ModelInfo } from '~/lib/modules/llm/types';
3+
import type { LanguageModelV1 } from 'ai';
4+
import type { IProviderSetting } from '~/types/model';
5+
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
6+
7+
interface AWSBedRockConfig {
8+
region: string;
9+
accessKeyId: string;
10+
secretAccessKey: string;
11+
sessionToken?: string;
12+
}
13+
14+
export default class AmazonBedrockProvider extends BaseProvider {
15+
name = 'AmazonBedrock';
16+
getApiKeyLink = 'https://console.aws.amazon.com/iam/home';
17+
18+
config = {
19+
apiTokenKey: 'AWS_BEDROCK_CONFIG',
20+
};
21+
22+
staticModels: ModelInfo[] = [
23+
{
24+
name: 'anthropic.claude-3-5-sonnet-20240620-v1:0',
25+
label: 'Claude 3.5 Sonnet (Bedrock)',
26+
provider: 'AmazonBedrock',
27+
maxTokenAllowed: 4096,
28+
},
29+
{
30+
name: 'anthropic.claude-3-sonnet-20240229-v1:0',
31+
label: 'Claude 3 Sonnet (Bedrock)',
32+
provider: 'AmazonBedrock',
33+
maxTokenAllowed: 4096,
34+
},
35+
{
36+
name: 'anthropic.claude-3-haiku-20240307-v1:0',
37+
label: 'Claude 3 Haiku (Bedrock)',
38+
provider: 'AmazonBedrock',
39+
maxTokenAllowed: 4096,
40+
},
41+
{
42+
name: 'amazon.nova-pro-v1:0',
43+
label: 'Amazon Nova Pro (Bedrock)',
44+
provider: 'AmazonBedrock',
45+
maxTokenAllowed: 5120,
46+
},
47+
{
48+
name: 'amazon.nova-lite-v1:0',
49+
label: 'Amazon Nova Lite (Bedrock)',
50+
provider: 'AmazonBedrock',
51+
maxTokenAllowed: 5120,
52+
},
53+
{
54+
name: 'mistral.mistral-large-2402-v1:0',
55+
label: 'Mistral Large 24.02 (Bedrock)',
56+
provider: 'AmazonBedrock',
57+
maxTokenAllowed: 8192,
58+
},
59+
];
60+
61+
private _parseAndValidateConfig(apiKey: string): AWSBedRockConfig {
62+
let parsedConfig: AWSBedRockConfig;
63+
64+
try {
65+
parsedConfig = JSON.parse(apiKey);
66+
} catch {
67+
throw new Error(
68+
'Invalid AWS Bedrock configuration format. Please provide a valid JSON string containing region, accessKeyId, and secretAccessKey.',
69+
);
70+
}
71+
72+
const { region, accessKeyId, secretAccessKey, sessionToken } = parsedConfig;
73+
74+
if (!region || !accessKeyId || !secretAccessKey) {
75+
throw new Error(
76+
'Missing required AWS credentials. Configuration must include region, accessKeyId, and secretAccessKey.',
77+
);
78+
}
79+
80+
return {
81+
region,
82+
accessKeyId,
83+
secretAccessKey,
84+
...(sessionToken && { sessionToken }),
85+
};
86+
}
87+
88+
getModelInstance(options: {
89+
model: string;
90+
serverEnv: any;
91+
apiKeys?: Record<string, string>;
92+
providerSettings?: Record<string, IProviderSetting>;
93+
}): LanguageModelV1 {
94+
const { model, serverEnv, apiKeys, providerSettings } = options;
95+
96+
const { apiKey } = this.getProviderBaseUrlAndKey({
97+
apiKeys,
98+
providerSettings: providerSettings?.[this.name],
99+
serverEnv: serverEnv as any,
100+
defaultBaseUrlKey: '',
101+
defaultApiTokenKey: 'AWS_BEDROCK_CONFIG',
102+
});
103+
104+
if (!apiKey) {
105+
throw new Error(`Missing API key for ${this.name} provider`);
106+
}
107+
108+
const config = this._parseAndValidateConfig(apiKey);
109+
const bedrock = createAmazonBedrock(config);
110+
111+
return bedrock(model);
112+
}
113+
}

app/lib/modules/llm/registry.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import PerplexityProvider from './providers/perplexity';
1414
import TogetherProvider from './providers/together';
1515
import XAIProvider from './providers/xai';
1616
import HyperbolicProvider from './providers/hyperbolic';
17+
import AmazonBedrockProvider from './providers/amazon-bedrock';
1718

1819
export {
1920
AnthropicProvider,
@@ -32,4 +33,5 @@ export {
3233
XAIProvider,
3334
TogetherProvider,
3435
LMStudioProvider,
36+
AmazonBedrockProvider,
3537
};

docker-compose.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ services:
2323
- XAI_API_KEY=${XAI_API_KEY}
2424
- TOGETHER_API_KEY=${TOGETHER_API_KEY}
2525
- TOGETHER_API_BASE_URL=${TOGETHER_API_BASE_URL}
26+
- AWS_BEDROCK_CONFIG=${AWS_BEDROCK_CONFIG}
2627
- VITE_LOG_LEVEL=${VITE_LOG_LEVEL:-debug}
2728
- DEFAULT_NUM_CTX=${DEFAULT_NUM_CTX:-32768}
2829
- RUNNING_IN_DOCKER=true
@@ -54,6 +55,7 @@ services:
5455
- OLLAMA_API_BASE_URL=${OLLAMA_API_BASE_URL}
5556
- TOGETHER_API_KEY=${TOGETHER_API_KEY}
5657
- TOGETHER_API_BASE_URL=${TOGETHER_API_BASE_URL}
58+
- AWS_BEDROCK_CONFIG=${AWS_BEDROCK_CONFIG}
5759
- VITE_LOG_LEVEL=${VITE_LOG_LEVEL:-debug}
5860
- DEFAULT_NUM_CTX=${DEFAULT_NUM_CTX:-32768}
5961
- RUNNING_IN_DOCKER=true

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"@ai-sdk/google": "^0.0.52",
3636
"@ai-sdk/mistral": "^0.0.43",
3737
"@ai-sdk/openai": "^0.0.66",
38+
"@ai-sdk/amazon-bedrock": "1.0.6",
3839
"@codemirror/autocomplete": "^6.18.3",
3940
"@codemirror/commands": "^6.7.1",
4041
"@codemirror/lang-cpp": "^6.0.2",

0 commit comments

Comments
 (0)