@ai-sdk/amazon-bedrock 5.0.0-beta.45 → 5.0.0-beta.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/anthropic/index.d.ts +10 -10
- package/dist/anthropic/index.js +65 -51
- package/dist/anthropic/index.js.map +1 -1
- package/dist/index.d.ts +21 -21
- package/dist/index.js +338 -298
- package/dist/index.js.map +1 -1
- package/docs/08-amazon-bedrock.mdx +66 -66
- package/package.json +3 -3
- package/src/{bedrock-api-types.ts → amazon-bedrock-api-types.ts} +60 -55
- package/src/{bedrock-chat-options.ts → amazon-bedrock-chat-language-model-options.ts} +7 -7
- package/src/{bedrock-chat-language-model.ts → amazon-bedrock-chat-language-model.ts} +211 -190
- package/src/{bedrock-embedding-options.ts → amazon-bedrock-embedding-model-options.ts} +1 -1
- package/src/{bedrock-embedding-model.ts → amazon-bedrock-embedding-model.ts} +31 -24
- package/src/{bedrock-error.ts → amazon-bedrock-error.ts} +1 -1
- package/src/{bedrock-event-stream-decoder.ts → amazon-bedrock-event-stream-decoder.ts} +1 -1
- package/src/{bedrock-event-stream-response-handler.ts → amazon-bedrock-event-stream-response-handler.ts} +3 -3
- package/src/{bedrock-image-model.ts → amazon-bedrock-image-model.ts} +40 -36
- package/src/amazon-bedrock-image-settings.ts +9 -0
- package/src/{bedrock-prepare-tools.ts → amazon-bedrock-prepare-tools.ts} +18 -17
- package/src/{bedrock-provider.ts → amazon-bedrock-provider.ts} +40 -38
- package/src/amazon-bedrock-reasoning-metadata.ts +10 -0
- package/src/{bedrock-sigv4-fetch.ts → amazon-bedrock-sigv4-fetch.ts} +13 -7
- package/src/anthropic/amazon-bedrock-anthropic-fetch.ts +104 -0
- package/src/anthropic/{bedrock-anthropic-options.ts → amazon-bedrock-anthropic-options.ts} +1 -1
- package/src/anthropic/{bedrock-anthropic-provider.ts → amazon-bedrock-anthropic-provider.ts} +18 -16
- package/src/anthropic/index.ts +19 -7
- package/src/{convert-bedrock-usage.ts → convert-amazon-bedrock-usage.ts} +3 -3
- package/src/{convert-to-bedrock-chat-messages.ts → convert-to-amazon-bedrock-chat-messages.ts} +92 -59
- package/src/index.ts +15 -8
- package/src/{map-bedrock-finish-reason.ts → map-amazon-bedrock-finish-reason.ts} +3 -3
- package/src/reranking/{bedrock-reranking-api.ts → amazon-bedrock-reranking-api.ts} +3 -3
- package/src/reranking/{bedrock-reranking-options.ts → amazon-bedrock-reranking-model-options.ts} +1 -1
- package/src/reranking/{bedrock-reranking-model.ts → amazon-bedrock-reranking-model.ts} +29 -21
- package/src/anthropic/bedrock-anthropic-fetch.ts +0 -94
- package/src/bedrock-image-settings.ts +0 -6
- package/src/bedrock-reasoning-metadata.ts +0 -10
|
@@ -105,7 +105,7 @@ _Usage:_
|
|
|
105
105
|
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
106
106
|
import { fromNodeProviderChain } from '@aws-sdk/credential-providers';
|
|
107
107
|
|
|
108
|
-
const
|
|
108
|
+
const amazonBedrock = createAmazonBedrock({
|
|
109
109
|
region: 'us-east-1',
|
|
110
110
|
credentialProvider: fromNodeProviderChain(),
|
|
111
111
|
});
|
|
@@ -113,10 +113,10 @@ const bedrock = createAmazonBedrock({
|
|
|
113
113
|
|
|
114
114
|
## Provider Instance
|
|
115
115
|
|
|
116
|
-
You can import the default provider instance `
|
|
116
|
+
You can import the default provider instance `amazonBedrock` from `@ai-sdk/amazon-bedrock`:
|
|
117
117
|
|
|
118
118
|
```ts
|
|
119
|
-
import {
|
|
119
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
120
120
|
```
|
|
121
121
|
|
|
122
122
|
If you need a customized setup, you can import `createAmazonBedrock` from `@ai-sdk/amazon-bedrock` and create a provider instance with your settings:
|
|
@@ -124,7 +124,7 @@ If you need a customized setup, you can import `createAmazonBedrock` from `@ai-s
|
|
|
124
124
|
```ts
|
|
125
125
|
import { createAmazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
126
126
|
|
|
127
|
-
const
|
|
127
|
+
const amazonBedrock = createAmazonBedrock({
|
|
128
128
|
region: 'us-east-1',
|
|
129
129
|
accessKeyId: 'xxxxxxxxx',
|
|
130
130
|
secretAccessKey: 'xxxxxxxxx',
|
|
@@ -195,14 +195,14 @@ You can create models that call the Bedrock API using the provider instance.
|
|
|
195
195
|
The first argument is the model id, e.g. `meta.llama3-70b-instruct-v1:0`.
|
|
196
196
|
|
|
197
197
|
```ts
|
|
198
|
-
const model =
|
|
198
|
+
const model = amazonBedrock('meta.llama3-70b-instruct-v1:0');
|
|
199
199
|
```
|
|
200
200
|
|
|
201
201
|
Amazon Bedrock models also support some model specific provider options that are not part of the [standard call settings](/docs/ai-sdk-core/settings).
|
|
202
202
|
You can pass them in the `providerOptions` argument:
|
|
203
203
|
|
|
204
204
|
```ts
|
|
205
|
-
const model =
|
|
205
|
+
const model = amazonBedrock('anthropic.claude-3-sonnet-20240229-v1:0');
|
|
206
206
|
|
|
207
207
|
await generateText({
|
|
208
208
|
model,
|
|
@@ -219,11 +219,11 @@ Documentation for additional settings based on the selected model can be found w
|
|
|
219
219
|
You can use Amazon Bedrock language models to generate text with the `generateText` function:
|
|
220
220
|
|
|
221
221
|
```ts
|
|
222
|
-
import {
|
|
222
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
223
223
|
import { generateText } from 'ai';
|
|
224
224
|
|
|
225
225
|
const { text } = await generateText({
|
|
226
|
-
model:
|
|
226
|
+
model: amazonBedrock('meta.llama3-70b-instruct-v1:0'),
|
|
227
227
|
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
228
228
|
});
|
|
229
229
|
```
|
|
@@ -241,11 +241,11 @@ Amazon Bedrock language models can also be used in the `streamText` function
|
|
|
241
241
|
The Amazon Bedrock provider supports file inputs, e.g. PDF files.
|
|
242
242
|
|
|
243
243
|
```ts
|
|
244
|
-
import {
|
|
244
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
245
245
|
import { generateText } from 'ai';
|
|
246
246
|
|
|
247
247
|
const result = await generateText({
|
|
248
|
-
model:
|
|
248
|
+
model: amazonBedrock('anthropic.claude-3-haiku-20240307-v1:0'),
|
|
249
249
|
messages: [
|
|
250
250
|
{
|
|
251
251
|
role: 'user',
|
|
@@ -267,10 +267,10 @@ const result = await generateText({
|
|
|
267
267
|
You can use the `bedrock` provider options to utilize [Amazon Bedrock Guardrails](https://aws.amazon.com/bedrock/guardrails/):
|
|
268
268
|
|
|
269
269
|
```ts
|
|
270
|
-
import { type
|
|
270
|
+
import { type AmazonBedrockLanguageModelChatOptions } from '@ai-sdk/amazon-bedrock';
|
|
271
271
|
|
|
272
272
|
const result = await generateText({
|
|
273
|
-
model:
|
|
273
|
+
model: amazonBedrock('anthropic.claude-3-sonnet-20240229-v1:0'),
|
|
274
274
|
prompt: 'Write a story about space exploration.',
|
|
275
275
|
providerOptions: {
|
|
276
276
|
bedrock: {
|
|
@@ -280,7 +280,7 @@ const result = await generateText({
|
|
|
280
280
|
trace: 'enabled' as const,
|
|
281
281
|
streamProcessingMode: 'async',
|
|
282
282
|
},
|
|
283
|
-
} satisfies
|
|
283
|
+
} satisfies AmazonBedrockLanguageModelChatOptions,
|
|
284
284
|
},
|
|
285
285
|
});
|
|
286
286
|
```
|
|
@@ -303,13 +303,13 @@ Amazon Bedrock supports citations for document-based inputs across compatible mo
|
|
|
303
303
|
- Models can cite specific parts of documents you provide, making it easier to trace information back to its source (Not Supported Yet)
|
|
304
304
|
|
|
305
305
|
```ts
|
|
306
|
-
import {
|
|
306
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
307
307
|
import { generateText, Output } from 'ai';
|
|
308
308
|
import { z } from 'zod';
|
|
309
309
|
import fs from 'fs';
|
|
310
310
|
|
|
311
311
|
const result = await generateText({
|
|
312
|
-
model:
|
|
312
|
+
model: amazonBedrock('apac.anthropic.claude-sonnet-4-20250514-v1:0'),
|
|
313
313
|
output: Output.object({
|
|
314
314
|
schema: z.object({
|
|
315
315
|
summary: z.string().describe('Summary of the PDF document'),
|
|
@@ -377,14 +377,14 @@ Cache usage information is returned in the `providerMetadata` object. See exampl
|
|
|
377
377
|
</Note>
|
|
378
378
|
|
|
379
379
|
```ts
|
|
380
|
-
import {
|
|
380
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
381
381
|
import { generateText } from 'ai';
|
|
382
382
|
|
|
383
383
|
const cyberpunkAnalysis =
|
|
384
384
|
'... literary analysis of cyberpunk themes and concepts ...';
|
|
385
385
|
|
|
386
386
|
const result = await generateText({
|
|
387
|
-
model:
|
|
387
|
+
model: amazonBedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'),
|
|
388
388
|
messages: [
|
|
389
389
|
{
|
|
390
390
|
role: 'system',
|
|
@@ -413,14 +413,14 @@ console.log(result.providerMetadata?.bedrock?.usage);
|
|
|
413
413
|
Cache points also work with streaming responses:
|
|
414
414
|
|
|
415
415
|
```ts
|
|
416
|
-
import {
|
|
416
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
417
417
|
import { streamText } from 'ai';
|
|
418
418
|
|
|
419
419
|
const cyberpunkAnalysis =
|
|
420
420
|
'... literary analysis of cyberpunk themes and concepts ...';
|
|
421
421
|
|
|
422
422
|
const result = streamText({
|
|
423
|
-
model:
|
|
423
|
+
model: amazonBedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'),
|
|
424
424
|
messages: [
|
|
425
425
|
{
|
|
426
426
|
role: 'assistant',
|
|
@@ -477,19 +477,19 @@ Amazon Bedrock supports model creator-specific reasoning features:
|
|
|
477
477
|
|
|
478
478
|
```ts
|
|
479
479
|
import {
|
|
480
|
-
|
|
481
|
-
type
|
|
480
|
+
amazonBedrock,
|
|
481
|
+
type AmazonBedrockLanguageModelChatOptions,
|
|
482
482
|
} from '@ai-sdk/amazon-bedrock';
|
|
483
483
|
import { generateText } from 'ai';
|
|
484
484
|
|
|
485
485
|
// Anthropic example
|
|
486
486
|
const anthropicResult = await generateText({
|
|
487
|
-
model:
|
|
487
|
+
model: amazonBedrock('us.anthropic.claude-sonnet-4-5-20250929-v1:0'),
|
|
488
488
|
prompt: 'How many people will live in the world in 2040?',
|
|
489
489
|
providerOptions: {
|
|
490
490
|
bedrock: {
|
|
491
491
|
reasoningConfig: { type: 'enabled', budgetTokens: 1024 },
|
|
492
|
-
} satisfies
|
|
492
|
+
} satisfies AmazonBedrockLanguageModelChatOptions,
|
|
493
493
|
},
|
|
494
494
|
});
|
|
495
495
|
|
|
@@ -498,12 +498,12 @@ console.log(anthropicResult.text); // text response
|
|
|
498
498
|
|
|
499
499
|
// Nova 2 example
|
|
500
500
|
const amazonResult = await generateText({
|
|
501
|
-
model:
|
|
501
|
+
model: amazonBedrock('us.amazon.nova-2-lite-v1:0'),
|
|
502
502
|
prompt: 'How many people will live in the world in 2040?',
|
|
503
503
|
providerOptions: {
|
|
504
504
|
bedrock: {
|
|
505
505
|
reasoningConfig: { type: 'enabled', maxReasoningEffort: 'medium' },
|
|
506
|
-
} satisfies
|
|
506
|
+
} satisfies AmazonBedrockLanguageModelChatOptions,
|
|
507
507
|
},
|
|
508
508
|
});
|
|
509
509
|
|
|
@@ -520,18 +520,18 @@ Amazon Bedrock supports selecting an inference service tier per request via the
|
|
|
520
520
|
|
|
521
521
|
```ts
|
|
522
522
|
import {
|
|
523
|
-
|
|
524
|
-
type
|
|
523
|
+
amazonBedrock,
|
|
524
|
+
type AmazonBedrockLanguageModelChatOptions,
|
|
525
525
|
} from '@ai-sdk/amazon-bedrock';
|
|
526
526
|
import { generateText } from 'ai';
|
|
527
527
|
|
|
528
528
|
const result = await generateText({
|
|
529
|
-
model:
|
|
529
|
+
model: amazonBedrock('us.anthropic.claude-sonnet-4-20250514-v1:0'),
|
|
530
530
|
prompt: 'Summarize this support ticket backlog.',
|
|
531
531
|
providerOptions: {
|
|
532
532
|
bedrock: {
|
|
533
533
|
serviceTier: 'priority',
|
|
534
|
-
} satisfies
|
|
534
|
+
} satisfies AmazonBedrockLanguageModelChatOptions,
|
|
535
535
|
},
|
|
536
536
|
});
|
|
537
537
|
```
|
|
@@ -551,18 +551,18 @@ Claude Sonnet 4 models on Amazon Bedrock support an extended context window of u
|
|
|
551
551
|
|
|
552
552
|
```ts
|
|
553
553
|
import {
|
|
554
|
-
|
|
555
|
-
type
|
|
554
|
+
amazonBedrock,
|
|
555
|
+
type AmazonBedrockLanguageModelChatOptions,
|
|
556
556
|
} from '@ai-sdk/amazon-bedrock';
|
|
557
557
|
import { generateText } from 'ai';
|
|
558
558
|
|
|
559
559
|
const result = await generateText({
|
|
560
|
-
model:
|
|
560
|
+
model: amazonBedrock('us.anthropic.claude-sonnet-4-20250514-v1:0'),
|
|
561
561
|
prompt: 'analyze this large document...',
|
|
562
562
|
providerOptions: {
|
|
563
563
|
bedrock: {
|
|
564
564
|
anthropicBeta: ['context-1m-2025-08-07'],
|
|
565
|
-
} satisfies
|
|
565
|
+
} satisfies AmazonBedrockLanguageModelChatOptions,
|
|
566
566
|
},
|
|
567
567
|
});
|
|
568
568
|
```
|
|
@@ -587,7 +587,7 @@ They are available via the `tools` property of the provider instance.
|
|
|
587
587
|
The Bash Tool allows running bash commands. Here's how to create and use it:
|
|
588
588
|
|
|
589
589
|
```ts
|
|
590
|
-
const bashTool =
|
|
590
|
+
const bashTool = amazonBedrock.tools.bash_20241022({
|
|
591
591
|
execute: async ({ command, restart }) => {
|
|
592
592
|
// Implement your bash command execution logic here
|
|
593
593
|
// Return the result of the command execution
|
|
@@ -607,7 +607,7 @@ The Text Editor Tool provides functionality for viewing and editing text files.
|
|
|
607
607
|
**For Claude 4 models (Opus & Sonnet):**
|
|
608
608
|
|
|
609
609
|
```ts
|
|
610
|
-
const textEditorTool =
|
|
610
|
+
const textEditorTool = amazonBedrock.tools.textEditor_20250429({
|
|
611
611
|
execute: async ({
|
|
612
612
|
command,
|
|
613
613
|
path,
|
|
@@ -627,7 +627,7 @@ const textEditorTool = bedrock.tools.textEditor_20250429({
|
|
|
627
627
|
**For Claude 3.5 Sonnet and earlier models:**
|
|
628
628
|
|
|
629
629
|
```ts
|
|
630
|
-
const textEditorTool =
|
|
630
|
+
const textEditorTool = amazonBedrock.tools.textEditor_20241022({
|
|
631
631
|
execute: async ({
|
|
632
632
|
command,
|
|
633
633
|
path,
|
|
@@ -663,7 +663,7 @@ When using the Text Editor Tool, make sure to name the key in the tools object c
|
|
|
663
663
|
```ts
|
|
664
664
|
// For Claude 4 models
|
|
665
665
|
const response = await generateText({
|
|
666
|
-
model:
|
|
666
|
+
model: amazonBedrock('us.anthropic.claude-sonnet-4-20250514-v1:0'),
|
|
667
667
|
prompt:
|
|
668
668
|
"Create a new file called example.txt, write 'Hello World' to it, and run 'cat example.txt' in the terminal",
|
|
669
669
|
tools: {
|
|
@@ -673,7 +673,7 @@ const response = await generateText({
|
|
|
673
673
|
|
|
674
674
|
// For Claude 3.5 Sonnet and earlier
|
|
675
675
|
const response = await generateText({
|
|
676
|
-
model:
|
|
676
|
+
model: amazonBedrock('anthropic.claude-3-5-sonnet-20241022-v2:0'),
|
|
677
677
|
prompt:
|
|
678
678
|
"Create a new file called example.txt, write 'Hello World' to it, and run 'cat example.txt' in the terminal",
|
|
679
679
|
tools: {
|
|
@@ -687,7 +687,7 @@ const response = await generateText({
|
|
|
687
687
|
The Computer Tool enables control of keyboard and mouse actions on a computer:
|
|
688
688
|
|
|
689
689
|
```ts
|
|
690
|
-
const computerTool =
|
|
690
|
+
const computerTool = amazonBedrock.tools.computer_20241022({
|
|
691
691
|
displayWidthPx: 1920,
|
|
692
692
|
displayHeightPx: 1080,
|
|
693
693
|
displayNumber: 0, // Optional, for X11 environments
|
|
@@ -810,18 +810,18 @@ You can create models that call the Bedrock API [Bedrock API](https://docs.aws.a
|
|
|
810
810
|
using the `.embedding()` factory method.
|
|
811
811
|
|
|
812
812
|
```ts
|
|
813
|
-
const model =
|
|
813
|
+
const model = amazonBedrock.embedding('amazon.titan-embed-text-v1');
|
|
814
814
|
```
|
|
815
815
|
|
|
816
816
|
Bedrock Titan embedding model amazon.titan-embed-text-v2:0 supports several additional settings.
|
|
817
817
|
You can pass them as an options argument:
|
|
818
818
|
|
|
819
819
|
```ts
|
|
820
|
-
import {
|
|
820
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
821
821
|
import { type AmazonBedrockEmbeddingModelOptions } from '@ai-sdk/amazon-bedrock';
|
|
822
822
|
import { embed } from 'ai';
|
|
823
823
|
|
|
824
|
-
const model =
|
|
824
|
+
const model = amazonBedrock.embedding('amazon.titan-embed-text-v2:0');
|
|
825
825
|
|
|
826
826
|
const { embedding } = await embed({
|
|
827
827
|
model,
|
|
@@ -850,12 +850,12 @@ The following optional provider options are available for Bedrock Titan embeddin
|
|
|
850
850
|
Amazon Nova embedding models support additional provider options:
|
|
851
851
|
|
|
852
852
|
```ts
|
|
853
|
-
import {
|
|
853
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
854
854
|
import { type AmazonBedrockEmbeddingModelOptions } from '@ai-sdk/amazon-bedrock';
|
|
855
855
|
import { embed } from 'ai';
|
|
856
856
|
|
|
857
857
|
const { embedding } = await embed({
|
|
858
|
-
model:
|
|
858
|
+
model: amazonBedrock.embedding('amazon.nova-embed-text-v2:0'),
|
|
859
859
|
value: 'sunny day at the beach',
|
|
860
860
|
providerOptions: {
|
|
861
861
|
bedrock: {
|
|
@@ -886,12 +886,12 @@ The following optional provider options are available for Nova embedding models:
|
|
|
886
886
|
Cohere embedding models on Bedrock require an `inputType` and support truncation:
|
|
887
887
|
|
|
888
888
|
```ts
|
|
889
|
-
import {
|
|
889
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
890
890
|
import { type AmazonBedrockEmbeddingModelOptions } from '@ai-sdk/amazon-bedrock';
|
|
891
891
|
import { embed } from 'ai';
|
|
892
892
|
|
|
893
893
|
const { embedding } = await embed({
|
|
894
|
-
model:
|
|
894
|
+
model: amazonBedrock.embedding('cohere.embed-english-v3'),
|
|
895
895
|
value: 'sunny day at the beach',
|
|
896
896
|
providerOptions: {
|
|
897
897
|
bedrock: {
|
|
@@ -928,13 +928,13 @@ You can create models that call the [Bedrock Rerank API](https://docs.aws.amazon
|
|
|
928
928
|
using the `.reranking()` factory method.
|
|
929
929
|
|
|
930
930
|
```ts
|
|
931
|
-
const model =
|
|
931
|
+
const model = amazonBedrock.reranking('cohere.rerank-v3-5:0');
|
|
932
932
|
```
|
|
933
933
|
|
|
934
934
|
You can use Amazon Bedrock reranking models to rerank documents with the `rerank` function:
|
|
935
935
|
|
|
936
936
|
```ts
|
|
937
|
-
import {
|
|
937
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
938
938
|
import { rerank } from 'ai';
|
|
939
939
|
|
|
940
940
|
const documents = [
|
|
@@ -944,7 +944,7 @@ const documents = [
|
|
|
944
944
|
];
|
|
945
945
|
|
|
946
946
|
const { ranking } = await rerank({
|
|
947
|
-
model:
|
|
947
|
+
model: amazonBedrock.reranking('cohere.rerank-v3-5:0'),
|
|
948
948
|
documents,
|
|
949
949
|
query: 'talk about rain',
|
|
950
950
|
topN: 2,
|
|
@@ -960,11 +960,11 @@ console.log(ranking);
|
|
|
960
960
|
Amazon Bedrock reranking models support additional provider options that can be passed via `providerOptions.bedrock`:
|
|
961
961
|
|
|
962
962
|
```ts
|
|
963
|
-
import {
|
|
963
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
964
964
|
import { rerank } from 'ai';
|
|
965
965
|
|
|
966
966
|
const { ranking } = await rerank({
|
|
967
|
-
model:
|
|
967
|
+
model: amazonBedrock.reranking('cohere.rerank-v3-5:0'),
|
|
968
968
|
documents: ['sunny day at the beach', 'rainy afternoon in the city'],
|
|
969
969
|
query: 'talk about rain',
|
|
970
970
|
providerOptions: {
|
|
@@ -1006,17 +1006,17 @@ Overview](https://docs.aws.amazon.com/ai/responsible-ai/nova-canvas/overview.htm
|
|
|
1006
1006
|
</Note>
|
|
1007
1007
|
|
|
1008
1008
|
```ts
|
|
1009
|
-
const model =
|
|
1009
|
+
const model = amazonBedrock.image('amazon.nova-canvas-v1:0');
|
|
1010
1010
|
```
|
|
1011
1011
|
|
|
1012
1012
|
You can then generate images with the `generateImage` function:
|
|
1013
1013
|
|
|
1014
1014
|
```ts
|
|
1015
|
-
import {
|
|
1015
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
1016
1016
|
import { generateImage } from 'ai';
|
|
1017
1017
|
|
|
1018
1018
|
const { image } = await generateImage({
|
|
1019
|
-
model:
|
|
1019
|
+
model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
|
|
1020
1020
|
prompt: 'A beautiful sunset over a calm ocean',
|
|
1021
1021
|
size: '512x512',
|
|
1022
1022
|
seed: 42,
|
|
@@ -1026,11 +1026,11 @@ const { image } = await generateImage({
|
|
|
1026
1026
|
You can also pass the `providerOptions` object to the `generateImage` function to customize the generation behavior:
|
|
1027
1027
|
|
|
1028
1028
|
```ts
|
|
1029
|
-
import {
|
|
1029
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
1030
1030
|
import { generateImage } from 'ai';
|
|
1031
1031
|
|
|
1032
1032
|
const { image } = await generateImage({
|
|
1033
|
-
model:
|
|
1033
|
+
model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
|
|
1034
1034
|
prompt: 'A beautiful sunset over a calm ocean',
|
|
1035
1035
|
size: '512x512',
|
|
1036
1036
|
seed: 42,
|
|
@@ -1083,7 +1083,7 @@ Create variations of an existing image while maintaining its core characteristic
|
|
|
1083
1083
|
const imageBuffer = readFileSync('./input-image.png');
|
|
1084
1084
|
|
|
1085
1085
|
const { images } = await generateImage({
|
|
1086
|
-
model:
|
|
1086
|
+
model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
|
|
1087
1087
|
prompt: {
|
|
1088
1088
|
text: 'Modernize the style, photo-realistic, 8k, hdr',
|
|
1089
1089
|
images: [imageBuffer],
|
|
@@ -1112,7 +1112,7 @@ Edit specific parts of an image. You can define the area to modify using either
|
|
|
1112
1112
|
const imageBuffer = readFileSync('./input-image.png');
|
|
1113
1113
|
|
|
1114
1114
|
const { images } = await generateImage({
|
|
1115
|
-
model:
|
|
1115
|
+
model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
|
|
1116
1116
|
prompt: {
|
|
1117
1117
|
text: 'a cute corgi dog in the same style',
|
|
1118
1118
|
images: [imageBuffer],
|
|
@@ -1133,7 +1133,7 @@ const image = readFileSync('./input-image.png');
|
|
|
1133
1133
|
const mask = readFileSync('./mask.png'); // White pixels = area to change
|
|
1134
1134
|
|
|
1135
1135
|
const { images } = await generateImage({
|
|
1136
|
-
model:
|
|
1136
|
+
model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
|
|
1137
1137
|
prompt: {
|
|
1138
1138
|
text: 'A sunlit indoor lounge area with a pool containing a flamingo',
|
|
1139
1139
|
images: [image],
|
|
@@ -1154,7 +1154,7 @@ Extend an image beyond its original boundaries:
|
|
|
1154
1154
|
const imageBuffer = readFileSync('./input-image.png');
|
|
1155
1155
|
|
|
1156
1156
|
const { images } = await generateImage({
|
|
1157
|
-
model:
|
|
1157
|
+
model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
|
|
1158
1158
|
prompt: {
|
|
1159
1159
|
text: 'A beautiful sunset landscape with mountains',
|
|
1160
1160
|
images: [imageBuffer],
|
|
@@ -1181,7 +1181,7 @@ Remove the background from an image:
|
|
|
1181
1181
|
const imageBuffer = readFileSync('./input-image.png');
|
|
1182
1182
|
|
|
1183
1183
|
const { images } = await generateImage({
|
|
1184
|
-
model:
|
|
1184
|
+
model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
|
|
1185
1185
|
prompt: {
|
|
1186
1186
|
images: [imageBuffer],
|
|
1187
1187
|
},
|
|
@@ -1224,7 +1224,7 @@ You can customize the generation behavior with optional options:
|
|
|
1224
1224
|
|
|
1225
1225
|
```ts
|
|
1226
1226
|
await generateImage({
|
|
1227
|
-
model:
|
|
1227
|
+
model: amazonBedrock.image('amazon.nova-canvas-v1:0'),
|
|
1228
1228
|
prompt: 'A beautiful sunset over a calm ocean',
|
|
1229
1229
|
size: '512x512',
|
|
1230
1230
|
seed: 42,
|
|
@@ -1259,11 +1259,11 @@ The Amazon Bedrock provider will return the response headers associated with
|
|
|
1259
1259
|
network requests made of the Bedrock servers.
|
|
1260
1260
|
|
|
1261
1261
|
```ts
|
|
1262
|
-
import {
|
|
1262
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
1263
1263
|
import { generateText } from 'ai';
|
|
1264
1264
|
|
|
1265
1265
|
const { text } = await generateText({
|
|
1266
|
-
model:
|
|
1266
|
+
model: amazonBedrock('meta.llama3-70b-instruct-v1:0'),
|
|
1267
1267
|
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
1268
1268
|
});
|
|
1269
1269
|
|
|
@@ -1286,11 +1286,11 @@ be useful for correlating Bedrock API calls with requests made by the AI SDK:
|
|
|
1286
1286
|
This information is also available with `streamText`:
|
|
1287
1287
|
|
|
1288
1288
|
```ts
|
|
1289
|
-
import {
|
|
1289
|
+
import { amazonBedrock } from '@ai-sdk/amazon-bedrock';
|
|
1290
1290
|
import { streamText } from 'ai';
|
|
1291
1291
|
|
|
1292
1292
|
const result = streamText({
|
|
1293
|
-
model:
|
|
1293
|
+
model: amazonBedrock('meta.llama3-70b-instruct-v1:0'),
|
|
1294
1294
|
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
1295
1295
|
});
|
|
1296
1296
|
for await (const textPart of result.textStream) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/amazon-bedrock",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.47",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"@smithy/eventstream-codec": "^4.0.1",
|
|
39
39
|
"@smithy/util-utf8": "^4.0.0",
|
|
40
40
|
"aws4fetch": "^1.0.20",
|
|
41
|
-
"@ai-sdk/anthropic": "4.0.0-beta.
|
|
41
|
+
"@ai-sdk/anthropic": "4.0.0-beta.42",
|
|
42
42
|
"@ai-sdk/provider": "4.0.0-beta.14",
|
|
43
|
-
"@ai-sdk/provider-utils": "5.0.0-beta.
|
|
43
|
+
"@ai-sdk/provider-utils": "5.0.0-beta.30"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "20.17.24",
|