@ai-sdk/amazon-bedrock 5.0.0-beta.2 → 5.0.0-beta.3
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 +8 -0
- package/dist/anthropic/index.d.mts +4 -4
- package/dist/anthropic/index.d.ts +4 -4
- package/dist/anthropic/index.js +2 -2
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +2 -2
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/index.d.mts +12 -12
- package/dist/index.d.ts +12 -12
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +6 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/anthropic/bedrock-anthropic-provider.ts +6 -6
- package/src/bedrock-chat-language-model.ts +26 -26
- package/src/bedrock-embedding-model.ts +5 -5
- package/src/bedrock-image-model.ts +9 -9
- package/src/bedrock-prepare-tools.ts +6 -6
- package/src/bedrock-provider.ts +17 -17
- package/src/convert-bedrock-usage.ts +2 -2
- package/src/convert-to-bedrock-chat-messages.ts +10 -10
- package/src/map-bedrock-finish-reason.ts +2 -2
- package/src/reranking/bedrock-reranking-model.ts +5 -5
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.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -38,7 +38,7 @@
|
|
|
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.3",
|
|
42
42
|
"@ai-sdk/provider": "4.0.0-beta.0",
|
|
43
43
|
"@ai-sdk/provider-utils": "5.0.0-beta.1"
|
|
44
44
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
LanguageModelV4,
|
|
3
3
|
NoSuchModelError,
|
|
4
|
-
|
|
4
|
+
ProviderV4,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
7
|
FetchFunction,
|
|
@@ -49,16 +49,16 @@ const BEDROCK_TOOL_BETA_MAP: Record<string, string> = {
|
|
|
49
49
|
computer_20241022: 'computer-use-2024-10-22',
|
|
50
50
|
};
|
|
51
51
|
|
|
52
|
-
export interface BedrockAnthropicProvider extends
|
|
52
|
+
export interface BedrockAnthropicProvider extends ProviderV4 {
|
|
53
53
|
/**
|
|
54
54
|
* Creates a model for text generation.
|
|
55
55
|
*/
|
|
56
|
-
(modelId: BedrockAnthropicModelId):
|
|
56
|
+
(modelId: BedrockAnthropicModelId): LanguageModelV4;
|
|
57
57
|
|
|
58
58
|
/**
|
|
59
59
|
* Creates a model for text generation.
|
|
60
60
|
*/
|
|
61
|
-
languageModel(modelId: BedrockAnthropicModelId):
|
|
61
|
+
languageModel(modelId: BedrockAnthropicModelId): LanguageModelV4;
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Anthropic-specific computer use tool.
|
|
@@ -333,7 +333,7 @@ export function createBedrockAnthropic(
|
|
|
333
333
|
return createChatModel(modelId);
|
|
334
334
|
};
|
|
335
335
|
|
|
336
|
-
provider.specificationVersion = '
|
|
336
|
+
provider.specificationVersion = 'v4' as const;
|
|
337
337
|
provider.languageModel = createChatModel;
|
|
338
338
|
provider.chat = createChatModel;
|
|
339
339
|
provider.messages = createChatModel;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JSONObject,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
LanguageModelV4,
|
|
4
|
+
LanguageModelV4CallOptions,
|
|
5
|
+
LanguageModelV4Content,
|
|
6
|
+
LanguageModelV4FinishReason,
|
|
7
|
+
LanguageModelV4FunctionTool,
|
|
8
|
+
LanguageModelV4GenerateResult,
|
|
9
|
+
LanguageModelV4Reasoning,
|
|
10
|
+
LanguageModelV4StreamPart,
|
|
11
|
+
LanguageModelV4StreamResult,
|
|
12
|
+
SharedV4ProviderMetadata,
|
|
13
|
+
SharedV4Warning,
|
|
14
14
|
} from '@ai-sdk/provider';
|
|
15
15
|
import {
|
|
16
16
|
FetchFunction,
|
|
@@ -48,8 +48,8 @@ type BedrockChatConfig = {
|
|
|
48
48
|
generateId: () => string;
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
export class BedrockChatLanguageModel implements
|
|
52
|
-
readonly specificationVersion = '
|
|
51
|
+
export class BedrockChatLanguageModel implements LanguageModelV4 {
|
|
52
|
+
readonly specificationVersion = 'v4';
|
|
53
53
|
readonly provider = 'amazon-bedrock';
|
|
54
54
|
|
|
55
55
|
constructor(
|
|
@@ -71,9 +71,9 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
71
71
|
tools,
|
|
72
72
|
toolChoice,
|
|
73
73
|
providerOptions,
|
|
74
|
-
}:
|
|
74
|
+
}: LanguageModelV4CallOptions): Promise<{
|
|
75
75
|
command: BedrockConverseInput;
|
|
76
|
-
warnings:
|
|
76
|
+
warnings: SharedV4Warning[];
|
|
77
77
|
usesJsonResponseTool: boolean;
|
|
78
78
|
betas: Set<string>;
|
|
79
79
|
}> {
|
|
@@ -85,7 +85,7 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
85
85
|
schema: amazonBedrockLanguageModelOptions,
|
|
86
86
|
})) ?? {};
|
|
87
87
|
|
|
88
|
-
const warnings:
|
|
88
|
+
const warnings: SharedV4Warning[] = [];
|
|
89
89
|
|
|
90
90
|
if (frequencyPenalty != null) {
|
|
91
91
|
warnings.push({
|
|
@@ -147,7 +147,7 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
147
147
|
responseFormat?.type === 'json' &&
|
|
148
148
|
responseFormat.schema != null;
|
|
149
149
|
|
|
150
|
-
const jsonResponseTool:
|
|
150
|
+
const jsonResponseTool: LanguageModelV4FunctionTool | undefined =
|
|
151
151
|
responseFormat?.type === 'json' &&
|
|
152
152
|
responseFormat.schema != null &&
|
|
153
153
|
!useNativeStructuredOutput
|
|
@@ -411,8 +411,8 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
411
411
|
}
|
|
412
412
|
|
|
413
413
|
async doGenerate(
|
|
414
|
-
options:
|
|
415
|
-
): Promise<
|
|
414
|
+
options: LanguageModelV4CallOptions,
|
|
415
|
+
): Promise<LanguageModelV4GenerateResult> {
|
|
416
416
|
const {
|
|
417
417
|
command: args,
|
|
418
418
|
warnings,
|
|
@@ -435,7 +435,7 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
435
435
|
fetch: this.config.fetch,
|
|
436
436
|
});
|
|
437
437
|
|
|
438
|
-
const content: Array<
|
|
438
|
+
const content: Array<LanguageModelV4Content> = [];
|
|
439
439
|
let isJsonResponseFromTool = false;
|
|
440
440
|
|
|
441
441
|
// map response content to content array
|
|
@@ -448,7 +448,7 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
448
448
|
// reasoning
|
|
449
449
|
if (part.reasoningContent) {
|
|
450
450
|
if ('reasoningText' in part.reasoningContent) {
|
|
451
|
-
const reasoning:
|
|
451
|
+
const reasoning: LanguageModelV4Reasoning = {
|
|
452
452
|
type: 'reasoning',
|
|
453
453
|
text: part.reasoningContent.reasoningText.text,
|
|
454
454
|
};
|
|
@@ -566,8 +566,8 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
566
566
|
}
|
|
567
567
|
|
|
568
568
|
async doStream(
|
|
569
|
-
options:
|
|
570
|
-
): Promise<
|
|
569
|
+
options: LanguageModelV4CallOptions,
|
|
570
|
+
): Promise<LanguageModelV4StreamResult> {
|
|
571
571
|
const {
|
|
572
572
|
command: args,
|
|
573
573
|
warnings,
|
|
@@ -591,12 +591,12 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
591
591
|
fetch: this.config.fetch,
|
|
592
592
|
});
|
|
593
593
|
|
|
594
|
-
let finishReason:
|
|
594
|
+
let finishReason: LanguageModelV4FinishReason = {
|
|
595
595
|
unified: 'other',
|
|
596
596
|
raw: undefined,
|
|
597
597
|
};
|
|
598
598
|
let usage: BedrockUsage | undefined = undefined;
|
|
599
|
-
let providerMetadata:
|
|
599
|
+
let providerMetadata: SharedV4ProviderMetadata | undefined = undefined;
|
|
600
600
|
let isJsonResponseFromTool = false;
|
|
601
601
|
let stopSequence: string | null = null;
|
|
602
602
|
|
|
@@ -616,7 +616,7 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
616
616
|
stream: response.pipeThrough(
|
|
617
617
|
new TransformStream<
|
|
618
618
|
ParseResult<z.infer<typeof BedrockStreamSchema>>,
|
|
619
|
-
|
|
619
|
+
LanguageModelV4StreamPart
|
|
620
620
|
>({
|
|
621
621
|
start(controller) {
|
|
622
622
|
controller.enqueue({ type: 'stream-start', warnings });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
EmbeddingModelV4,
|
|
3
3
|
TooManyEmbeddingValuesForCallError,
|
|
4
4
|
} from '@ai-sdk/provider';
|
|
5
5
|
import {
|
|
@@ -25,10 +25,10 @@ type BedrockEmbeddingConfig = {
|
|
|
25
25
|
fetch?: FetchFunction;
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
type DoEmbedResponse = Awaited<ReturnType<
|
|
28
|
+
type DoEmbedResponse = Awaited<ReturnType<EmbeddingModelV4['doEmbed']>>;
|
|
29
29
|
|
|
30
|
-
export class BedrockEmbeddingModel implements
|
|
31
|
-
readonly specificationVersion = '
|
|
30
|
+
export class BedrockEmbeddingModel implements EmbeddingModelV4 {
|
|
31
|
+
readonly specificationVersion = 'v4';
|
|
32
32
|
readonly provider = 'amazon-bedrock';
|
|
33
33
|
readonly maxEmbeddingsPerCall = 1;
|
|
34
34
|
readonly supportsParallelCalls = true;
|
|
@@ -48,7 +48,7 @@ export class BedrockEmbeddingModel implements EmbeddingModelV3 {
|
|
|
48
48
|
headers,
|
|
49
49
|
abortSignal,
|
|
50
50
|
providerOptions,
|
|
51
|
-
}: Parameters<
|
|
51
|
+
}: Parameters<EmbeddingModelV4['doEmbed']>[0]): Promise<DoEmbedResponse> {
|
|
52
52
|
if (values.length > this.maxEmbeddingsPerCall) {
|
|
53
53
|
throw new TooManyEmbeddingValuesForCallError({
|
|
54
54
|
provider: this.provider,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
ImageModelV4,
|
|
3
|
+
ImageModelV4File,
|
|
4
|
+
SharedV4Warning,
|
|
5
5
|
} from '@ai-sdk/provider';
|
|
6
6
|
import {
|
|
7
7
|
FetchFunction,
|
|
@@ -29,8 +29,8 @@ type BedrockImageModelConfig = {
|
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
export class BedrockImageModel implements
|
|
33
|
-
readonly specificationVersion = '
|
|
32
|
+
export class BedrockImageModel implements ImageModelV4 {
|
|
33
|
+
readonly specificationVersion = 'v4';
|
|
34
34
|
readonly provider = 'amazon-bedrock';
|
|
35
35
|
|
|
36
36
|
get maxImagesPerCall(): number {
|
|
@@ -58,10 +58,10 @@ export class BedrockImageModel implements ImageModelV3 {
|
|
|
58
58
|
abortSignal,
|
|
59
59
|
files,
|
|
60
60
|
mask,
|
|
61
|
-
}: Parameters<
|
|
62
|
-
Awaited<ReturnType<
|
|
61
|
+
}: Parameters<ImageModelV4['doGenerate']>[0]): Promise<
|
|
62
|
+
Awaited<ReturnType<ImageModelV4['doGenerate']>>
|
|
63
63
|
> {
|
|
64
|
-
const warnings: Array<
|
|
64
|
+
const warnings: Array<SharedV4Warning> = [];
|
|
65
65
|
const [width, height] = size ? size.split('x').map(Number) : [];
|
|
66
66
|
|
|
67
67
|
const hasFiles = files != null && files.length > 0;
|
|
@@ -265,7 +265,7 @@ export class BedrockImageModel implements ImageModelV3 {
|
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
-
function getBase64Data(file:
|
|
268
|
+
function getBase64Data(file: ImageModelV4File): string {
|
|
269
269
|
if (file.type === 'url') {
|
|
270
270
|
throw new Error(
|
|
271
271
|
'URL-based images are not supported for Amazon Bedrock image editing. ' +
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JSONObject,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
LanguageModelV4CallOptions,
|
|
4
|
+
SharedV4Warning,
|
|
5
5
|
UnsupportedFunctionalityError,
|
|
6
6
|
} from '@ai-sdk/provider';
|
|
7
7
|
import { asSchema } from '@ai-sdk/provider-utils';
|
|
@@ -16,16 +16,16 @@ export async function prepareTools({
|
|
|
16
16
|
toolChoice,
|
|
17
17
|
modelId,
|
|
18
18
|
}: {
|
|
19
|
-
tools:
|
|
20
|
-
toolChoice?:
|
|
19
|
+
tools: LanguageModelV4CallOptions['tools'];
|
|
20
|
+
toolChoice?: LanguageModelV4CallOptions['toolChoice'];
|
|
21
21
|
modelId: string;
|
|
22
22
|
}): Promise<{
|
|
23
23
|
toolConfig: BedrockToolConfiguration;
|
|
24
24
|
additionalTools: Record<string, unknown> | undefined;
|
|
25
25
|
betas: Set<string>;
|
|
26
|
-
toolWarnings:
|
|
26
|
+
toolWarnings: SharedV4Warning[];
|
|
27
27
|
}> {
|
|
28
|
-
const toolWarnings:
|
|
28
|
+
const toolWarnings: SharedV4Warning[] = [];
|
|
29
29
|
const betas = new Set<string>();
|
|
30
30
|
|
|
31
31
|
if (tools == null || tools.length === 0) {
|
package/src/bedrock-provider.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { anthropicTools } from '@ai-sdk/anthropic/internal';
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
EmbeddingModelV4,
|
|
4
|
+
ImageModelV4,
|
|
5
|
+
LanguageModelV4,
|
|
6
|
+
ProviderV4,
|
|
7
|
+
RerankingModelV4,
|
|
8
8
|
} from '@ai-sdk/provider';
|
|
9
9
|
import {
|
|
10
10
|
FetchFunction,
|
|
@@ -107,50 +107,50 @@ export interface AmazonBedrockProviderSettings {
|
|
|
107
107
|
generateId?: () => string;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
|
-
export interface AmazonBedrockProvider extends
|
|
111
|
-
(modelId: BedrockChatModelId):
|
|
110
|
+
export interface AmazonBedrockProvider extends ProviderV4 {
|
|
111
|
+
(modelId: BedrockChatModelId): LanguageModelV4;
|
|
112
112
|
|
|
113
|
-
languageModel(modelId: BedrockChatModelId):
|
|
113
|
+
languageModel(modelId: BedrockChatModelId): LanguageModelV4;
|
|
114
114
|
|
|
115
115
|
/**
|
|
116
116
|
* Creates a model for text embeddings.
|
|
117
117
|
*/
|
|
118
|
-
embedding(modelId: BedrockEmbeddingModelId):
|
|
118
|
+
embedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV4;
|
|
119
119
|
|
|
120
120
|
/**
|
|
121
121
|
* Creates a model for text embeddings.
|
|
122
122
|
*/
|
|
123
|
-
embeddingModel(modelId: BedrockEmbeddingModelId):
|
|
123
|
+
embeddingModel(modelId: BedrockEmbeddingModelId): EmbeddingModelV4;
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
126
|
* @deprecated Use `embedding` instead.
|
|
127
127
|
*/
|
|
128
|
-
textEmbedding(modelId: BedrockEmbeddingModelId):
|
|
128
|
+
textEmbedding(modelId: BedrockEmbeddingModelId): EmbeddingModelV4;
|
|
129
129
|
|
|
130
130
|
/**
|
|
131
131
|
* @deprecated Use `embeddingModel` instead.
|
|
132
132
|
*/
|
|
133
|
-
textEmbeddingModel(modelId: BedrockEmbeddingModelId):
|
|
133
|
+
textEmbeddingModel(modelId: BedrockEmbeddingModelId): EmbeddingModelV4;
|
|
134
134
|
|
|
135
135
|
/**
|
|
136
136
|
* Creates a model for image generation.
|
|
137
137
|
*/
|
|
138
|
-
image(modelId: BedrockImageModelId):
|
|
138
|
+
image(modelId: BedrockImageModelId): ImageModelV4;
|
|
139
139
|
|
|
140
140
|
/**
|
|
141
141
|
* Creates a model for image generation.
|
|
142
142
|
*/
|
|
143
|
-
imageModel(modelId: BedrockImageModelId):
|
|
143
|
+
imageModel(modelId: BedrockImageModelId): ImageModelV4;
|
|
144
144
|
|
|
145
145
|
/**
|
|
146
146
|
* Creates a model for reranking documents.
|
|
147
147
|
*/
|
|
148
|
-
reranking(modelId: BedrockRerankingModelId):
|
|
148
|
+
reranking(modelId: BedrockRerankingModelId): RerankingModelV4;
|
|
149
149
|
|
|
150
150
|
/**
|
|
151
151
|
* Creates a model for reranking documents.
|
|
152
152
|
*/
|
|
153
|
-
rerankingModel(modelId: BedrockRerankingModelId):
|
|
153
|
+
rerankingModel(modelId: BedrockRerankingModelId): RerankingModelV4;
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
156
|
* Anthropic-specific tools that can be used with Anthropic models on Bedrock.
|
|
@@ -330,7 +330,7 @@ export function createAmazonBedrock(
|
|
|
330
330
|
fetch: fetchFunction,
|
|
331
331
|
});
|
|
332
332
|
|
|
333
|
-
provider.specificationVersion = '
|
|
333
|
+
provider.specificationVersion = 'v4' as const;
|
|
334
334
|
provider.languageModel = createChatModel;
|
|
335
335
|
provider.embedding = createEmbeddingModel;
|
|
336
336
|
provider.embeddingModel = createEmbeddingModel;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4Usage } from '@ai-sdk/provider';
|
|
2
2
|
|
|
3
3
|
export type BedrockUsage = {
|
|
4
4
|
inputTokens: number;
|
|
@@ -10,7 +10,7 @@ export type BedrockUsage = {
|
|
|
10
10
|
|
|
11
11
|
export function convertBedrockUsage(
|
|
12
12
|
usage: BedrockUsage | undefined | null,
|
|
13
|
-
):
|
|
13
|
+
): LanguageModelV4Usage {
|
|
14
14
|
if (usage == null) {
|
|
15
15
|
return {
|
|
16
16
|
inputTokens: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JSONObject,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
LanguageModelV4Message,
|
|
4
|
+
LanguageModelV4Prompt,
|
|
5
|
+
SharedV4ProviderMetadata,
|
|
6
6
|
UnsupportedFunctionalityError,
|
|
7
7
|
} from '@ai-sdk/provider';
|
|
8
8
|
import {
|
|
@@ -28,7 +28,7 @@ import { bedrockFilePartProviderOptions } from './bedrock-chat-options';
|
|
|
28
28
|
import { normalizeToolCallId } from './normalize-tool-call-id';
|
|
29
29
|
|
|
30
30
|
function getCachePoint(
|
|
31
|
-
providerMetadata:
|
|
31
|
+
providerMetadata: SharedV4ProviderMetadata | undefined,
|
|
32
32
|
): BedrockCachePoint | undefined {
|
|
33
33
|
const cachePointConfig = providerMetadata?.bedrock?.cachePoint as
|
|
34
34
|
| BedrockCachePoint['cachePoint']
|
|
@@ -42,7 +42,7 @@ function getCachePoint(
|
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
async function shouldEnableCitations(
|
|
45
|
-
providerMetadata:
|
|
45
|
+
providerMetadata: SharedV4ProviderMetadata | undefined,
|
|
46
46
|
): Promise<boolean> {
|
|
47
47
|
const bedrockOptions = await parseProviderOptions({
|
|
48
48
|
provider: 'bedrock',
|
|
@@ -54,7 +54,7 @@ async function shouldEnableCitations(
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export async function convertToBedrockChatMessages(
|
|
57
|
-
prompt:
|
|
57
|
+
prompt: LanguageModelV4Prompt,
|
|
58
58
|
isMistral: boolean = false,
|
|
59
59
|
): Promise<{
|
|
60
60
|
system: BedrockSystemMessages;
|
|
@@ -400,19 +400,19 @@ function trimIfLast(
|
|
|
400
400
|
|
|
401
401
|
type SystemBlock = {
|
|
402
402
|
type: 'system';
|
|
403
|
-
messages: Array<
|
|
403
|
+
messages: Array<LanguageModelV4Message & { role: 'system' }>;
|
|
404
404
|
};
|
|
405
405
|
type AssistantBlock = {
|
|
406
406
|
type: 'assistant';
|
|
407
|
-
messages: Array<
|
|
407
|
+
messages: Array<LanguageModelV4Message & { role: 'assistant' }>;
|
|
408
408
|
};
|
|
409
409
|
type UserBlock = {
|
|
410
410
|
type: 'user';
|
|
411
|
-
messages: Array<
|
|
411
|
+
messages: Array<LanguageModelV4Message & { role: 'user' | 'tool' }>;
|
|
412
412
|
};
|
|
413
413
|
|
|
414
414
|
function groupIntoBlocks(
|
|
415
|
-
prompt:
|
|
415
|
+
prompt: LanguageModelV4Prompt,
|
|
416
416
|
): Array<SystemBlock | AssistantBlock | UserBlock> {
|
|
417
417
|
const blocks: Array<SystemBlock | AssistantBlock | UserBlock> = [];
|
|
418
418
|
let currentBlock: SystemBlock | AssistantBlock | UserBlock | undefined =
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { LanguageModelV4FinishReason } from '@ai-sdk/provider';
|
|
2
2
|
import { BedrockStopReason } from './bedrock-api-types';
|
|
3
3
|
|
|
4
4
|
export function mapBedrockFinishReason(
|
|
5
5
|
finishReason: BedrockStopReason,
|
|
6
6
|
isJsonResponseFromTool?: boolean,
|
|
7
|
-
):
|
|
7
|
+
): LanguageModelV4FinishReason['unified'] {
|
|
8
8
|
switch (finishReason) {
|
|
9
9
|
case 'stop_sequence':
|
|
10
10
|
case 'end_turn':
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RerankingModelV4 } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
3
|
FetchFunction,
|
|
4
4
|
Resolvable,
|
|
@@ -26,10 +26,10 @@ type BedrockRerankingConfig = {
|
|
|
26
26
|
fetch?: FetchFunction;
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
type DoRerankResponse = Awaited<ReturnType<
|
|
29
|
+
type DoRerankResponse = Awaited<ReturnType<RerankingModelV4['doRerank']>>;
|
|
30
30
|
|
|
31
|
-
export class BedrockRerankingModel implements
|
|
32
|
-
readonly specificationVersion = '
|
|
31
|
+
export class BedrockRerankingModel implements RerankingModelV4 {
|
|
32
|
+
readonly specificationVersion = 'v4';
|
|
33
33
|
readonly provider = 'amazon-bedrock';
|
|
34
34
|
|
|
35
35
|
constructor(
|
|
@@ -44,7 +44,7 @@ export class BedrockRerankingModel implements RerankingModelV3 {
|
|
|
44
44
|
topN,
|
|
45
45
|
abortSignal,
|
|
46
46
|
providerOptions,
|
|
47
|
-
}: Parameters<
|
|
47
|
+
}: Parameters<RerankingModelV4['doRerank']>[0]): Promise<DoRerankResponse> {
|
|
48
48
|
const bedrockOptions = await parseProviderOptions({
|
|
49
49
|
provider: 'bedrock',
|
|
50
50
|
providerOptions,
|