@ai-sdk/amazon-bedrock 4.0.67 → 4.0.69
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 +16 -0
- package/dist/anthropic/index.js +3 -3
- package/dist/anthropic/index.js.map +1 -1
- package/dist/anthropic/index.mjs +3 -3
- package/dist/anthropic/index.mjs.map +1 -1
- package/dist/index.js +26 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -12
- package/dist/index.mjs.map +1 -1
- package/docs/08-amazon-bedrock.mdx +1 -1
- package/package.json +3 -3
- package/src/anthropic/bedrock-anthropic-provider.ts +2 -2
- package/src/bedrock-chat-language-model.ts +29 -5
|
@@ -484,7 +484,7 @@ import { generateText } from 'ai';
|
|
|
484
484
|
|
|
485
485
|
// Anthropic example
|
|
486
486
|
const anthropicResult = await generateText({
|
|
487
|
-
model: bedrock('us.
|
|
487
|
+
model: bedrock('us.anthropic.claude-3-7-sonnet-20250219-v1:0'),
|
|
488
488
|
prompt: 'How many people will live in the world in 2040?',
|
|
489
489
|
providerOptions: {
|
|
490
490
|
bedrock: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/amazon-bedrock",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.69",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -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": "3.0.
|
|
41
|
+
"@ai-sdk/anthropic": "3.0.50",
|
|
42
42
|
"@ai-sdk/provider": "3.0.8",
|
|
43
|
-
"@ai-sdk/provider-utils": "4.0.
|
|
43
|
+
"@ai-sdk/provider-utils": "4.0.16"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "20.17.24",
|
|
@@ -319,8 +319,8 @@ export function createBedrockAnthropic(
|
|
|
319
319
|
|
|
320
320
|
// Bedrock Anthropic doesn't support URL sources, force download and base64 conversion
|
|
321
321
|
supportedUrls: () => ({}),
|
|
322
|
-
//
|
|
323
|
-
supportsNativeStructuredOutput:
|
|
322
|
+
// native structured output via output_config.format is supported on Bedrock
|
|
323
|
+
supportsNativeStructuredOutput: true,
|
|
324
324
|
});
|
|
325
325
|
|
|
326
326
|
const provider = function (modelId: BedrockAnthropicModelId) {
|
|
@@ -136,8 +136,21 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
+
const isAnthropicModel = this.modelId.includes('anthropic');
|
|
140
|
+
const isThinkingEnabled =
|
|
141
|
+
bedrockOptions.reasoningConfig?.type === 'enabled' ||
|
|
142
|
+
bedrockOptions.reasoningConfig?.type === 'adaptive';
|
|
143
|
+
|
|
144
|
+
const useNativeStructuredOutput =
|
|
145
|
+
isAnthropicModel &&
|
|
146
|
+
isThinkingEnabled &&
|
|
147
|
+
responseFormat?.type === 'json' &&
|
|
148
|
+
responseFormat.schema != null;
|
|
149
|
+
|
|
139
150
|
const jsonResponseTool: LanguageModelV3FunctionTool | undefined =
|
|
140
|
-
responseFormat?.type === 'json' &&
|
|
151
|
+
responseFormat?.type === 'json' &&
|
|
152
|
+
responseFormat.schema != null &&
|
|
153
|
+
!useNativeStructuredOutput
|
|
141
154
|
? {
|
|
142
155
|
type: 'function',
|
|
143
156
|
name: 'json',
|
|
@@ -176,15 +189,12 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
176
189
|
};
|
|
177
190
|
}
|
|
178
191
|
|
|
179
|
-
const isAnthropicModel = this.modelId.includes('anthropic');
|
|
180
192
|
const thinkingType = bedrockOptions.reasoningConfig?.type;
|
|
181
|
-
const isThinkingRequested =
|
|
182
|
-
thinkingType === 'enabled' || thinkingType === 'adaptive';
|
|
183
193
|
const thinkingBudget =
|
|
184
194
|
thinkingType === 'enabled'
|
|
185
195
|
? bedrockOptions.reasoningConfig?.budgetTokens
|
|
186
196
|
: undefined;
|
|
187
|
-
const isAnthropicThinkingEnabled = isAnthropicModel &&
|
|
197
|
+
const isAnthropicThinkingEnabled = isAnthropicModel && isThinkingEnabled;
|
|
188
198
|
|
|
189
199
|
const inferenceConfig = {
|
|
190
200
|
...(maxOutputTokens != null && { maxTokens: maxOutputTokens }),
|
|
@@ -244,6 +254,7 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
244
254
|
bedrockOptions.additionalModelRequestFields = {
|
|
245
255
|
...bedrockOptions.additionalModelRequestFields,
|
|
246
256
|
output_config: {
|
|
257
|
+
...bedrockOptions.additionalModelRequestFields?.output_config,
|
|
247
258
|
effort: maxReasoningEffort,
|
|
248
259
|
},
|
|
249
260
|
};
|
|
@@ -267,6 +278,19 @@ export class BedrockChatLanguageModel implements LanguageModelV3 {
|
|
|
267
278
|
}
|
|
268
279
|
}
|
|
269
280
|
|
|
281
|
+
if (useNativeStructuredOutput) {
|
|
282
|
+
bedrockOptions.additionalModelRequestFields = {
|
|
283
|
+
...bedrockOptions.additionalModelRequestFields,
|
|
284
|
+
output_config: {
|
|
285
|
+
...bedrockOptions.additionalModelRequestFields?.output_config,
|
|
286
|
+
format: {
|
|
287
|
+
type: 'json_schema',
|
|
288
|
+
schema: responseFormat!.schema,
|
|
289
|
+
},
|
|
290
|
+
},
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
270
294
|
if (isAnthropicThinkingEnabled && inferenceConfig.temperature != null) {
|
|
271
295
|
delete inferenceConfig.temperature;
|
|
272
296
|
warnings.push({
|