forked from stackblitz-labs/bolt.diy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'stackblitz-labs:main' into main
- Loading branch information
Showing
16 changed files
with
1,278 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.