mirror of
				https://github.com/stackblitz-labs/bolt.diy
				synced 2025-06-26 18:26:38 +00:00 
			
		
		
		
	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
This commit is contained in:
		
							parent
							
								
									7e39e924e1
								
							
						
					
					
						commit
						3ecac25a35
					
				
							
								
								
									
										11
									
								
								.env.example
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								.env.example
									
									
									
									
									
								
							@ -83,6 +83,17 @@ XAI_API_KEY=
 | 
			
		||||
# You only need this environment variable set if you want to use Perplexity models
 | 
			
		||||
PERPLEXITY_API_KEY=
 | 
			
		||||
 | 
			
		||||
# Get your AWS configuration
 | 
			
		||||
# https://console.aws.amazon.com/iam/home
 | 
			
		||||
# The JSON should include the following keys:
 | 
			
		||||
#   - region: The AWS region where Bedrock is available.
 | 
			
		||||
#   - accessKeyId: Your AWS access key ID.
 | 
			
		||||
#   - secretAccessKey: Your AWS secret access key.
 | 
			
		||||
#   - sessionToken (optional): Temporary session token if using an IAM role or temporary credentials.
 | 
			
		||||
# Example JSON:
 | 
			
		||||
# {"region": "us-east-1", "accessKeyId": "yourAccessKeyId", "secretAccessKey": "yourSecretAccessKey", "sessionToken": "yourSessionToken"}
 | 
			
		||||
AWS_BEDROCK_CONFIG=
 | 
			
		||||
 | 
			
		||||
# Include this environment variable if you want more logging for debugging locally
 | 
			
		||||
VITE_LOG_LEVEL=debug
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -28,6 +28,7 @@ ARG OLLAMA_API_BASE_URL
 | 
			
		||||
ARG XAI_API_KEY
 | 
			
		||||
ARG TOGETHER_API_KEY
 | 
			
		||||
ARG TOGETHER_API_BASE_URL
 | 
			
		||||
ARG AWS_BEDROCK_CONFIG
 | 
			
		||||
ARG VITE_LOG_LEVEL=debug
 | 
			
		||||
ARG DEFAULT_NUM_CTX
 | 
			
		||||
 | 
			
		||||
@ -42,6 +43,7 @@ ENV WRANGLER_SEND_METRICS=false \
 | 
			
		||||
    XAI_API_KEY=${XAI_API_KEY} \
 | 
			
		||||
    TOGETHER_API_KEY=${TOGETHER_API_KEY} \
 | 
			
		||||
    TOGETHER_API_BASE_URL=${TOGETHER_API_BASE_URL} \
 | 
			
		||||
    AWS_BEDROCK_CONFIG=${AWS_BEDROCK_CONFIG} \
 | 
			
		||||
    VITE_LOG_LEVEL=${VITE_LOG_LEVEL} \
 | 
			
		||||
    DEFAULT_NUM_CTX=${DEFAULT_NUM_CTX}
 | 
			
		||||
 | 
			
		||||
@ -80,6 +82,7 @@ ENV GROQ_API_KEY=${GROQ_API_KEY} \
 | 
			
		||||
    XAI_API_KEY=${XAI_API_KEY} \
 | 
			
		||||
    TOGETHER_API_KEY=${TOGETHER_API_KEY} \
 | 
			
		||||
    TOGETHER_API_BASE_URL=${TOGETHER_API_BASE_URL} \
 | 
			
		||||
    AWS_BEDROCK_CONFIG=${AWS_BEDROCK_CONFIG} \
 | 
			
		||||
    VITE_LOG_LEVEL=${VITE_LOG_LEVEL} \
 | 
			
		||||
    DEFAULT_NUM_CTX=${DEFAULT_NUM_CTX}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -74,6 +74,7 @@ bolt.diy was originally started by [Cole Medin](https://www.youtube.com/@ColeMed
 | 
			
		||||
- ⬜ Voice prompting
 | 
			
		||||
- ⬜ Azure Open AI API Integration
 | 
			
		||||
- ✅ Perplexity Integration (@meetpateltech)
 | 
			
		||||
- ✅ AWS Bedrock Integration (@kunjabijukchhe)
 | 
			
		||||
- ⬜ Vertex AI Integration
 | 
			
		||||
 | 
			
		||||
## Features
 | 
			
		||||
 | 
			
		||||
@ -22,6 +22,7 @@ const API_KEY_PROVIDERS = [
 | 
			
		||||
  'Perplexity',
 | 
			
		||||
  'Cohere',
 | 
			
		||||
  'AzureOpenAI',
 | 
			
		||||
  'AmazonBedrock',
 | 
			
		||||
] as const;
 | 
			
		||||
 | 
			
		||||
interface ApiKeys {
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										113
									
								
								app/lib/modules/llm/providers/amazon-bedrock.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								app/lib/modules/llm/providers/amazon-bedrock.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,113 @@
 | 
			
		||||
import { BaseProvider } from '~/lib/modules/llm/base-provider';
 | 
			
		||||
import type { ModelInfo } from '~/lib/modules/llm/types';
 | 
			
		||||
import type { LanguageModelV1 } from 'ai';
 | 
			
		||||
import type { IProviderSetting } from '~/types/model';
 | 
			
		||||
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
 | 
			
		||||
 | 
			
		||||
interface AWSBedRockConfig {
 | 
			
		||||
  region: string;
 | 
			
		||||
  accessKeyId: string;
 | 
			
		||||
  secretAccessKey: string;
 | 
			
		||||
  sessionToken?: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export default class AmazonBedrockProvider extends BaseProvider {
 | 
			
		||||
  name = 'AmazonBedrock';
 | 
			
		||||
  getApiKeyLink = 'https://console.aws.amazon.com/iam/home';
 | 
			
		||||
 | 
			
		||||
  config = {
 | 
			
		||||
    apiTokenKey: 'AWS_BEDROCK_CONFIG',
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  staticModels: ModelInfo[] = [
 | 
			
		||||
    {
 | 
			
		||||
      name: 'anthropic.claude-3-5-sonnet-20240620-v1:0',
 | 
			
		||||
      label: 'Claude 3.5 Sonnet (Bedrock)',
 | 
			
		||||
      provider: 'AmazonBedrock',
 | 
			
		||||
      maxTokenAllowed: 4096,
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      name: 'anthropic.claude-3-sonnet-20240229-v1:0',
 | 
			
		||||
      label: 'Claude 3 Sonnet (Bedrock)',
 | 
			
		||||
      provider: 'AmazonBedrock',
 | 
			
		||||
      maxTokenAllowed: 4096,
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      name: 'anthropic.claude-3-haiku-20240307-v1:0',
 | 
			
		||||
      label: 'Claude 3 Haiku (Bedrock)',
 | 
			
		||||
      provider: 'AmazonBedrock',
 | 
			
		||||
      maxTokenAllowed: 4096,
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      name: 'amazon.nova-pro-v1:0',
 | 
			
		||||
      label: 'Amazon Nova Pro (Bedrock)',
 | 
			
		||||
      provider: 'AmazonBedrock',
 | 
			
		||||
      maxTokenAllowed: 5120,
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      name: 'amazon.nova-lite-v1:0',
 | 
			
		||||
      label: 'Amazon Nova Lite (Bedrock)',
 | 
			
		||||
      provider: 'AmazonBedrock',
 | 
			
		||||
      maxTokenAllowed: 5120,
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      name: 'mistral.mistral-large-2402-v1:0',
 | 
			
		||||
      label: 'Mistral Large 24.02 (Bedrock)',
 | 
			
		||||
      provider: 'AmazonBedrock',
 | 
			
		||||
      maxTokenAllowed: 8192,
 | 
			
		||||
    },
 | 
			
		||||
  ];
 | 
			
		||||
 | 
			
		||||
  private _parseAndValidateConfig(apiKey: string): AWSBedRockConfig {
 | 
			
		||||
    let parsedConfig: AWSBedRockConfig;
 | 
			
		||||
 | 
			
		||||
    try {
 | 
			
		||||
      parsedConfig = JSON.parse(apiKey);
 | 
			
		||||
    } catch {
 | 
			
		||||
      throw new Error(
 | 
			
		||||
        'Invalid AWS Bedrock configuration format. Please provide a valid JSON string containing region, accessKeyId, and secretAccessKey.',
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const { region, accessKeyId, secretAccessKey, sessionToken } = parsedConfig;
 | 
			
		||||
 | 
			
		||||
    if (!region || !accessKeyId || !secretAccessKey) {
 | 
			
		||||
      throw new Error(
 | 
			
		||||
        'Missing required AWS credentials. Configuration must include region, accessKeyId, and secretAccessKey.',
 | 
			
		||||
      );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return {
 | 
			
		||||
      region,
 | 
			
		||||
      accessKeyId,
 | 
			
		||||
      secretAccessKey,
 | 
			
		||||
      ...(sessionToken && { sessionToken }),
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getModelInstance(options: {
 | 
			
		||||
    model: string;
 | 
			
		||||
    serverEnv: any;
 | 
			
		||||
    apiKeys?: Record<string, string>;
 | 
			
		||||
    providerSettings?: Record<string, IProviderSetting>;
 | 
			
		||||
  }): LanguageModelV1 {
 | 
			
		||||
    const { model, serverEnv, apiKeys, providerSettings } = options;
 | 
			
		||||
 | 
			
		||||
    const { apiKey } = this.getProviderBaseUrlAndKey({
 | 
			
		||||
      apiKeys,
 | 
			
		||||
      providerSettings: providerSettings?.[this.name],
 | 
			
		||||
      serverEnv: serverEnv as any,
 | 
			
		||||
      defaultBaseUrlKey: '',
 | 
			
		||||
      defaultApiTokenKey: 'AWS_BEDROCK_CONFIG',
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    if (!apiKey) {
 | 
			
		||||
      throw new Error(`Missing API key for ${this.name} provider`);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const config = this._parseAndValidateConfig(apiKey);
 | 
			
		||||
    const bedrock = createAmazonBedrock(config);
 | 
			
		||||
 | 
			
		||||
    return bedrock(model);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@ -14,6 +14,7 @@ import PerplexityProvider from './providers/perplexity';
 | 
			
		||||
import TogetherProvider from './providers/together';
 | 
			
		||||
import XAIProvider from './providers/xai';
 | 
			
		||||
import HyperbolicProvider from './providers/hyperbolic';
 | 
			
		||||
import AmazonBedrockProvider from './providers/amazon-bedrock';
 | 
			
		||||
 | 
			
		||||
export {
 | 
			
		||||
  AnthropicProvider,
 | 
			
		||||
@ -32,4 +33,5 @@ export {
 | 
			
		||||
  XAIProvider,
 | 
			
		||||
  TogetherProvider,
 | 
			
		||||
  LMStudioProvider,
 | 
			
		||||
  AmazonBedrockProvider,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -23,6 +23,7 @@ services:
 | 
			
		||||
      - XAI_API_KEY=${XAI_API_KEY}
 | 
			
		||||
      - TOGETHER_API_KEY=${TOGETHER_API_KEY}
 | 
			
		||||
      - TOGETHER_API_BASE_URL=${TOGETHER_API_BASE_URL}
 | 
			
		||||
      - AWS_BEDROCK_CONFIG=${AWS_BEDROCK_CONFIG}
 | 
			
		||||
      - VITE_LOG_LEVEL=${VITE_LOG_LEVEL:-debug}
 | 
			
		||||
      - DEFAULT_NUM_CTX=${DEFAULT_NUM_CTX:-32768}
 | 
			
		||||
      - RUNNING_IN_DOCKER=true
 | 
			
		||||
@ -54,6 +55,7 @@ services:
 | 
			
		||||
      - OLLAMA_API_BASE_URL=${OLLAMA_API_BASE_URL}
 | 
			
		||||
      - TOGETHER_API_KEY=${TOGETHER_API_KEY}
 | 
			
		||||
      - TOGETHER_API_BASE_URL=${TOGETHER_API_BASE_URL}
 | 
			
		||||
      - AWS_BEDROCK_CONFIG=${AWS_BEDROCK_CONFIG}
 | 
			
		||||
      - VITE_LOG_LEVEL=${VITE_LOG_LEVEL:-debug}
 | 
			
		||||
      - DEFAULT_NUM_CTX=${DEFAULT_NUM_CTX:-32768}
 | 
			
		||||
      - RUNNING_IN_DOCKER=true
 | 
			
		||||
 | 
			
		||||
@ -35,6 +35,7 @@
 | 
			
		||||
    "@ai-sdk/google": "^0.0.52",
 | 
			
		||||
    "@ai-sdk/mistral": "^0.0.43",
 | 
			
		||||
    "@ai-sdk/openai": "^0.0.66",
 | 
			
		||||
    "@ai-sdk/amazon-bedrock": "1.0.6",
 | 
			
		||||
    "@codemirror/autocomplete": "^6.18.3",
 | 
			
		||||
    "@codemirror/commands": "^6.7.1",
 | 
			
		||||
    "@codemirror/lang-cpp": "^6.0.2",
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										1075
									
								
								pnpm-lock.yaml
									
									
									
									
									
								
							
							
						
						
									
										1075
									
								
								pnpm-lock.yaml
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1
									
								
								public/icons/AmazonBedrock.svg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								public/icons/AmazonBedrock.svg
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
			
		||||
<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Bedrock</title><path d="M13.05 15.513h3.08c.214 0 .389.177.389.394v1.82a1.704 1.704 0 011.296 1.661c0 .943-.755 1.708-1.685 1.708-.931 0-1.686-.765-1.686-1.708 0-.807.554-1.484 1.297-1.662v-1.425h-2.69v4.663a.395.395 0 01-.188.338l-2.69 1.641a.385.385 0 01-.405-.002l-4.926-3.086a.395.395 0 01-.185-.336V16.3L2.196 14.87A.395.395 0 012 14.555L2 14.528V9.406c0-.14.073-.27.192-.34l2.465-1.462V4.448c0-.129.062-.249.165-.322l.021-.014L9.77 1.058a.385.385 0 01.407 0l2.69 1.675a.395.395 0 01.185.336V7.6h3.856V5.683a1.704 1.704 0 01-1.296-1.662c0-.943.755-1.708 1.685-1.708.931 0 1.685.765 1.685 1.708 0 .807-.553 1.484-1.296 1.662v2.311a.391.391 0 01-.389.394h-4.245v1.806h6.624a1.69 1.69 0 011.64-1.313c.93 0 1.685.764 1.685 1.707 0 .943-.754 1.708-1.685 1.708a1.69 1.69 0 01-1.64-1.314H13.05v1.937h4.953l.915 1.18a1.66 1.66 0 01.84-.227c.931 0 1.685.764 1.685 1.707 0 .943-.754 1.708-1.685 1.708-.93 0-1.685-.765-1.685-1.708 0-.346.102-.668.276-.937l-.724-.935H13.05v1.806zM9.973 1.856L7.93 3.122V6.09h-.778V3.604L5.435 4.669v2.945l2.11 1.36L9.712 7.61V5.334h.778V7.83c0 .136-.07.263-.184.335L7.963 9.638v2.081l1.422 1.009-.446.646-1.406-.998-1.53 1.005-.423-.66 1.605-1.055v-1.99L5.038 8.29l-2.26 1.34v1.676l1.972-1.189.398.677-2.37 1.429V14.3l2.166 1.258 2.27-1.368.397.677-2.176 1.311V19.3l1.876 1.175 2.365-1.426.398.678-2.017 1.216 1.918 1.201 2.298-1.403v-5.78l-4.758 2.893-.4-.675 5.158-3.136V3.289L9.972 1.856zM16.13 18.47a.913.913 0 00-.908.92c0 .507.406.918.908.918a.913.913 0 00.907-.919.913.913 0 00-.907-.92zm3.63-3.81a.913.913 0 00-.908.92c0 .508.406.92.907.92a.913.913 0 00.908-.92.913.913 0 00-.908-.92zm1.555-4.99a.913.913 0 00-.908.92c0 .507.407.918.908.918a.913.913 0 00.907-.919.913.913 0 00-.907-.92zM17.296 3.1a.913.913 0 00-.907.92c0 .508.406.92.907.92a.913.913 0 00.908-.92.913.913 0 00-.908-.92z"></path></svg>
 | 
			
		||||
| 
		 After Width: | Height: | Size: 2.0 KiB  | 
							
								
								
									
										1
									
								
								worker-configuration.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								worker-configuration.d.ts
									
									
									
									
										vendored
									
									
								
							@ -16,4 +16,5 @@ interface Env {
 | 
			
		||||
  MISTRAL_API_KEY: string;
 | 
			
		||||
  XAI_API_KEY: string;
 | 
			
		||||
  PERPLEXITY_API_KEY: string;
 | 
			
		||||
  AWS_BEDROCK_CONFIG: string;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user