bedrock-wrapper 2.4.1 → 2.4.2
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 +15 -0
- package/README.md +36 -0
- package/bedrock-models.js +26 -0
- package/bedrock-wrapper.js +16 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
|
|
4
|
+
## [2.4.2] - 2025-07-31 (Stop Sequences Support)
|
|
5
|
+
### Added
|
|
6
|
+
- Stop sequences support for all models
|
|
7
|
+
- OpenAI-compatible `stop` and `stop_sequences` parameters
|
|
8
|
+
- Automatic string-to-array conversion for compatibility
|
|
9
|
+
- Model-specific parameter mapping (stop_sequences for Claude, stopSequences for Nova, stop for Llama/Mistral)
|
|
10
|
+
- Enhanced request building logic to include stop sequences in appropriate API formats
|
|
11
|
+
- Comprehensive stop sequences testing and validation
|
|
12
|
+
|
|
13
|
+
### Technical Details
|
|
14
|
+
- Added `stop_sequences_param_name` configuration to all 26+ model definitions
|
|
15
|
+
- Updated request construction for both messages API and prompt-based models
|
|
16
|
+
- Supports both single string and array formats for stop sequences
|
|
17
|
+
- Maintains full backward compatibility with existing API usage
|
|
18
|
+
|
|
4
19
|
## [2.4.0] - 2025-07-24 (AWS Nova Models)
|
|
5
20
|
### Added
|
|
6
21
|
- Support for AWS Nova models
|
package/README.md
CHANGED
|
@@ -44,6 +44,7 @@ Bedrock Wrapper is an npm package that simplifies the integration of existing Op
|
|
|
44
44
|
"stream": true,
|
|
45
45
|
"temperature": LLM_TEMPERATURE,
|
|
46
46
|
"top_p": LLM_TOP_P,
|
|
47
|
+
"stop_sequences": ["STOP", "END"], // Optional: sequences that will stop generation
|
|
47
48
|
};
|
|
48
49
|
```
|
|
49
50
|
|
|
@@ -189,6 +190,41 @@ You can include multiple images in a single message by adding more image_url obj
|
|
|
189
190
|
|
|
190
191
|
---
|
|
191
192
|
|
|
193
|
+
### Stop Sequences
|
|
194
|
+
|
|
195
|
+
All models support stop sequences - custom text sequences that cause the model to stop generating. This is useful for controlling where the model stops its response.
|
|
196
|
+
|
|
197
|
+
```javascript
|
|
198
|
+
const openaiChatCompletionsCreateObject = {
|
|
199
|
+
"messages": messages,
|
|
200
|
+
"model": "Claude-3-5-Sonnet",
|
|
201
|
+
"max_tokens": 100,
|
|
202
|
+
"stop_sequences": ["STOP", "END", "\n\n"], // Array of stop sequences
|
|
203
|
+
// OR use single string format:
|
|
204
|
+
// "stop": "STOP"
|
|
205
|
+
};
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
**Features:**
|
|
209
|
+
- Compatible with OpenAI's `stop` parameter (single string or array)
|
|
210
|
+
- Also accepts `stop_sequences` parameter for explicit usage
|
|
211
|
+
- Automatic conversion between string and array formats
|
|
212
|
+
- Works with all 26+ supported models (Claude, Nova, Llama, Mistral)
|
|
213
|
+
- Model-specific parameter mapping handled automatically
|
|
214
|
+
|
|
215
|
+
**Example Usage:**
|
|
216
|
+
```javascript
|
|
217
|
+
// Stop generation when model tries to output "7"
|
|
218
|
+
const result = await bedrockWrapper(awsCreds, {
|
|
219
|
+
messages: [{ role: "user", content: "Count from 1 to 10" }],
|
|
220
|
+
model: "Claude-3-5-Sonnet",
|
|
221
|
+
stop_sequences: ["7"]
|
|
222
|
+
});
|
|
223
|
+
// Response: "1, 2, 3, 4, 5, 6," (stops before "7")
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
192
228
|
### 📢 P.S.
|
|
193
229
|
|
|
194
230
|
In case you missed it at the beginning of this doc, for an even easier setup, use the 🔀 [Bedrock Proxy Endpoint](https://github.com/jparkerweb/bedrock-proxy-endpoint) project to spin up your own custom OpenAI server endpoint (using the standard `baseUrl`, and `apiKey` params).
|
package/bedrock-models.js
CHANGED
|
@@ -19,6 +19,7 @@ export const bedrock_models = [
|
|
|
19
19
|
"display_role_names": true,
|
|
20
20
|
"max_tokens_param_name": "max_tokens",
|
|
21
21
|
"max_supported_response_tokens": 131072,
|
|
22
|
+
"stop_sequences_param_name": "stop_sequences",
|
|
22
23
|
"response_chunk_element": "delta.text",
|
|
23
24
|
"response_nonchunk_element": "content[0].text",
|
|
24
25
|
"thinking_response_chunk_element": "delta.thinking",
|
|
@@ -46,6 +47,7 @@ export const bedrock_models = [
|
|
|
46
47
|
"display_role_names": true,
|
|
47
48
|
"max_tokens_param_name": "max_tokens",
|
|
48
49
|
"max_supported_response_tokens": 131072,
|
|
50
|
+
"stop_sequences_param_name": "stop_sequences",
|
|
49
51
|
"response_chunk_element": "delta.text",
|
|
50
52
|
"response_nonchunk_element": "content[0].text",
|
|
51
53
|
"thinking_response_chunk_element": "delta.thinking",
|
|
@@ -77,6 +79,7 @@ export const bedrock_models = [
|
|
|
77
79
|
"display_role_names": true,
|
|
78
80
|
"max_tokens_param_name": "max_tokens",
|
|
79
81
|
"max_supported_response_tokens": 131072,
|
|
82
|
+
"stop_sequences_param_name": "stop_sequences",
|
|
80
83
|
"response_chunk_element": "delta.text",
|
|
81
84
|
"response_nonchunk_element": "content[0].text",
|
|
82
85
|
"thinking_response_chunk_element": "delta.thinking",
|
|
@@ -104,6 +107,7 @@ export const bedrock_models = [
|
|
|
104
107
|
"display_role_names": true,
|
|
105
108
|
"max_tokens_param_name": "max_tokens",
|
|
106
109
|
"max_supported_response_tokens": 131072,
|
|
110
|
+
"stop_sequences_param_name": "stop_sequences",
|
|
107
111
|
"response_chunk_element": "delta.text",
|
|
108
112
|
"response_nonchunk_element": "content[0].text",
|
|
109
113
|
"thinking_response_chunk_element": "delta.thinking",
|
|
@@ -135,6 +139,7 @@ export const bedrock_models = [
|
|
|
135
139
|
"display_role_names": true,
|
|
136
140
|
"max_tokens_param_name": "max_tokens",
|
|
137
141
|
"max_supported_response_tokens": 131072,
|
|
142
|
+
"stop_sequences_param_name": "stop_sequences",
|
|
138
143
|
"response_chunk_element": "delta.text",
|
|
139
144
|
"response_nonchunk_element": "content[0].text",
|
|
140
145
|
"thinking_response_chunk_element": "delta.thinking",
|
|
@@ -166,6 +171,7 @@ export const bedrock_models = [
|
|
|
166
171
|
"display_role_names": true,
|
|
167
172
|
"max_tokens_param_name": "max_tokens",
|
|
168
173
|
"max_supported_response_tokens": 131072,
|
|
174
|
+
"stop_sequences_param_name": "stop_sequences",
|
|
169
175
|
"response_chunk_element": "delta.text",
|
|
170
176
|
"response_nonchunk_element": "content[0].text",
|
|
171
177
|
"special_request_schema": {
|
|
@@ -190,6 +196,7 @@ export const bedrock_models = [
|
|
|
190
196
|
"display_role_names": true,
|
|
191
197
|
"max_tokens_param_name": "max_tokens",
|
|
192
198
|
"max_supported_response_tokens": 8192,
|
|
199
|
+
"stop_sequences_param_name": "stop_sequences",
|
|
193
200
|
"response_chunk_element": "delta.text",
|
|
194
201
|
"response_nonchunk_element": "content[0].text",
|
|
195
202
|
"special_request_schema": {
|
|
@@ -213,6 +220,7 @@ export const bedrock_models = [
|
|
|
213
220
|
"display_role_names": true,
|
|
214
221
|
"max_tokens_param_name": "max_tokens",
|
|
215
222
|
"max_supported_response_tokens": 8192,
|
|
223
|
+
"stop_sequences_param_name": "stop_sequences",
|
|
216
224
|
"response_chunk_element": "delta.text",
|
|
217
225
|
"response_nonchunk_element": "content[0].text",
|
|
218
226
|
"special_request_schema": {
|
|
@@ -236,6 +244,7 @@ export const bedrock_models = [
|
|
|
236
244
|
"display_role_names": true,
|
|
237
245
|
"max_tokens_param_name": "max_tokens",
|
|
238
246
|
"max_supported_response_tokens": 8192,
|
|
247
|
+
"stop_sequences_param_name": "stop_sequences",
|
|
239
248
|
"response_chunk_element": "delta.text",
|
|
240
249
|
"response_nonchunk_element": "content[0].text",
|
|
241
250
|
"special_request_schema": {
|
|
@@ -254,6 +263,7 @@ export const bedrock_models = [
|
|
|
254
263
|
"display_role_names": true,
|
|
255
264
|
"max_tokens_param_name": "max_tokens",
|
|
256
265
|
"max_supported_response_tokens": 8192,
|
|
266
|
+
"stop_sequences_param_name": "stop_sequences",
|
|
257
267
|
"response_chunk_element": "delta.text",
|
|
258
268
|
"response_nonchunk_element": "content[0].text",
|
|
259
269
|
"special_request_schema": {
|
|
@@ -291,6 +301,7 @@ export const bedrock_models = [
|
|
|
291
301
|
"display_role_names": true,
|
|
292
302
|
"max_tokens_param_name": "max_gen_len",
|
|
293
303
|
"max_supported_response_tokens": 2048,
|
|
304
|
+
"stop_sequences_param_name": "stop",
|
|
294
305
|
"response_chunk_element": "generation"
|
|
295
306
|
},
|
|
296
307
|
{
|
|
@@ -319,6 +330,7 @@ export const bedrock_models = [
|
|
|
319
330
|
"display_role_names": true,
|
|
320
331
|
"max_tokens_param_name": "max_gen_len",
|
|
321
332
|
"max_supported_response_tokens": 2048,
|
|
333
|
+
"stop_sequences_param_name": "stop",
|
|
322
334
|
"response_chunk_element": "generation"
|
|
323
335
|
},
|
|
324
336
|
{
|
|
@@ -347,6 +359,7 @@ export const bedrock_models = [
|
|
|
347
359
|
"display_role_names": true,
|
|
348
360
|
"max_tokens_param_name": "max_gen_len",
|
|
349
361
|
"max_supported_response_tokens": 2048,
|
|
362
|
+
"stop_sequences_param_name": "stop",
|
|
350
363
|
"response_chunk_element": "generation"
|
|
351
364
|
},
|
|
352
365
|
{
|
|
@@ -375,6 +388,7 @@ export const bedrock_models = [
|
|
|
375
388
|
"display_role_names": true,
|
|
376
389
|
"max_tokens_param_name": "max_gen_len",
|
|
377
390
|
"max_supported_response_tokens": 2048,
|
|
391
|
+
"stop_sequences_param_name": "stop",
|
|
378
392
|
"response_chunk_element": "generation"
|
|
379
393
|
},
|
|
380
394
|
{
|
|
@@ -403,6 +417,7 @@ export const bedrock_models = [
|
|
|
403
417
|
"display_role_names": true,
|
|
404
418
|
"max_tokens_param_name": "max_gen_len",
|
|
405
419
|
"max_supported_response_tokens": 2048,
|
|
420
|
+
"stop_sequences_param_name": "stop",
|
|
406
421
|
"response_chunk_element": "generation"
|
|
407
422
|
},
|
|
408
423
|
{
|
|
@@ -430,6 +445,7 @@ export const bedrock_models = [
|
|
|
430
445
|
"display_role_names": true,
|
|
431
446
|
"max_tokens_param_name": "max_gen_len",
|
|
432
447
|
"max_supported_response_tokens": 2048,
|
|
448
|
+
"stop_sequences_param_name": "stop",
|
|
433
449
|
"response_chunk_element": "generation"
|
|
434
450
|
},
|
|
435
451
|
{
|
|
@@ -457,6 +473,7 @@ export const bedrock_models = [
|
|
|
457
473
|
"display_role_names": true,
|
|
458
474
|
"max_tokens_param_name": "max_gen_len",
|
|
459
475
|
"max_supported_response_tokens": 2048,
|
|
476
|
+
"stop_sequences_param_name": "stop",
|
|
460
477
|
"response_chunk_element": "generation"
|
|
461
478
|
},
|
|
462
479
|
{
|
|
@@ -484,6 +501,7 @@ export const bedrock_models = [
|
|
|
484
501
|
"display_role_names": true,
|
|
485
502
|
"max_tokens_param_name": "max_gen_len",
|
|
486
503
|
"max_supported_response_tokens": 2048,
|
|
504
|
+
"stop_sequences_param_name": "stop",
|
|
487
505
|
"response_chunk_element": "generation"
|
|
488
506
|
},
|
|
489
507
|
{
|
|
@@ -511,6 +529,7 @@ export const bedrock_models = [
|
|
|
511
529
|
"display_role_names": true,
|
|
512
530
|
"max_tokens_param_name": "max_gen_len",
|
|
513
531
|
"max_supported_response_tokens": 2048,
|
|
532
|
+
"stop_sequences_param_name": "stop",
|
|
514
533
|
"response_chunk_element": "generation"
|
|
515
534
|
},
|
|
516
535
|
{
|
|
@@ -538,6 +557,7 @@ export const bedrock_models = [
|
|
|
538
557
|
"display_role_names": true,
|
|
539
558
|
"max_tokens_param_name": "max_gen_len",
|
|
540
559
|
"max_supported_response_tokens": 2048,
|
|
560
|
+
"stop_sequences_param_name": "stop",
|
|
541
561
|
"response_chunk_element": "generation"
|
|
542
562
|
},
|
|
543
563
|
{
|
|
@@ -552,6 +572,7 @@ export const bedrock_models = [
|
|
|
552
572
|
"display_role_names": true,
|
|
553
573
|
"max_tokens_param_name": "maxTokens",
|
|
554
574
|
"max_supported_response_tokens": 5000,
|
|
575
|
+
"stop_sequences_param_name": "stopSequences",
|
|
555
576
|
"response_chunk_element": "contentBlockDelta.delta.text",
|
|
556
577
|
"response_nonchunk_element": "output.message.content[0].text",
|
|
557
578
|
"special_request_schema": {
|
|
@@ -576,6 +597,7 @@ export const bedrock_models = [
|
|
|
576
597
|
"display_role_names": true,
|
|
577
598
|
"max_tokens_param_name": "maxTokens",
|
|
578
599
|
"max_supported_response_tokens": 5000,
|
|
600
|
+
"stop_sequences_param_name": "stopSequences",
|
|
579
601
|
"response_chunk_element": "contentBlockDelta.delta.text",
|
|
580
602
|
"response_nonchunk_element": "output.message.content[0].text",
|
|
581
603
|
"special_request_schema": {
|
|
@@ -600,6 +622,7 @@ export const bedrock_models = [
|
|
|
600
622
|
"display_role_names": true,
|
|
601
623
|
"max_tokens_param_name": "maxTokens",
|
|
602
624
|
"max_supported_response_tokens": 5000,
|
|
625
|
+
"stop_sequences_param_name": "stopSequences",
|
|
603
626
|
"response_chunk_element": "contentBlockDelta.delta.text",
|
|
604
627
|
"response_nonchunk_element": "output.message.content[0].text",
|
|
605
628
|
"special_request_schema": {
|
|
@@ -632,6 +655,7 @@ export const bedrock_models = [
|
|
|
632
655
|
"display_role_names": false,
|
|
633
656
|
"max_tokens_param_name": "max_tokens",
|
|
634
657
|
"max_supported_response_tokens": 8192,
|
|
658
|
+
"stop_sequences_param_name": "stop",
|
|
635
659
|
"response_chunk_element": "outputs[0].text"
|
|
636
660
|
},
|
|
637
661
|
{
|
|
@@ -659,6 +683,7 @@ export const bedrock_models = [
|
|
|
659
683
|
"display_role_names": false,
|
|
660
684
|
"max_tokens_param_name": "max_tokens",
|
|
661
685
|
"max_supported_response_tokens": 4096,
|
|
686
|
+
"stop_sequences_param_name": "stop",
|
|
662
687
|
"response_chunk_element": "outputs[0].text"
|
|
663
688
|
},
|
|
664
689
|
{
|
|
@@ -686,6 +711,7 @@ export const bedrock_models = [
|
|
|
686
711
|
"display_role_names": false,
|
|
687
712
|
"max_tokens_param_name": "max_tokens",
|
|
688
713
|
"max_supported_response_tokens": 8192,
|
|
714
|
+
"stop_sequences_param_name": "stop",
|
|
689
715
|
"response_chunk_element": "outputs[0].text"
|
|
690
716
|
},
|
|
691
717
|
];
|
package/bedrock-wrapper.js
CHANGED
|
@@ -64,7 +64,7 @@ async function processImage(imageInput) {
|
|
|
64
64
|
|
|
65
65
|
export async function* bedrockWrapper(awsCreds, openaiChatCompletionsCreateObject, { logging = false } = {} ) {
|
|
66
66
|
const { region, accessKeyId, secretAccessKey } = awsCreds;
|
|
67
|
-
let { messages, model, max_tokens, stream, temperature, top_p, include_thinking_data } = openaiChatCompletionsCreateObject;
|
|
67
|
+
let { messages, model, max_tokens, stream, temperature, top_p, include_thinking_data, stop, stop_sequences } = openaiChatCompletionsCreateObject;
|
|
68
68
|
|
|
69
69
|
|
|
70
70
|
let {awsModelId, awsModel} = findAwsModelWithId(model);
|
|
@@ -269,13 +269,17 @@ export async function* bedrockWrapper(awsCreds, openaiChatCompletionsCreateObjec
|
|
|
269
269
|
};
|
|
270
270
|
});
|
|
271
271
|
|
|
272
|
+
const stopSequencesValue = stop_sequences || stop;
|
|
272
273
|
const novaRequest = {
|
|
273
274
|
...awsModel.special_request_schema,
|
|
274
275
|
messages: novaMessages,
|
|
275
276
|
inferenceConfig: {
|
|
276
277
|
[awsModel.max_tokens_param_name]: max_gen_tokens,
|
|
277
278
|
temperature: temperature,
|
|
278
|
-
topP: top_p
|
|
279
|
+
topP: top_p,
|
|
280
|
+
...(awsModel.stop_sequences_param_name && stopSequencesValue && {
|
|
281
|
+
[awsModel.stop_sequences_param_name]: Array.isArray(stopSequencesValue) ? stopSequencesValue : [stopSequencesValue]
|
|
282
|
+
})
|
|
279
283
|
}
|
|
280
284
|
};
|
|
281
285
|
|
|
@@ -287,12 +291,16 @@ export async function* bedrockWrapper(awsCreds, openaiChatCompletionsCreateObjec
|
|
|
287
291
|
return novaRequest;
|
|
288
292
|
} else {
|
|
289
293
|
// Standard messages API format (Claude, etc.)
|
|
294
|
+
const stopSequencesValue = stop_sequences || stop;
|
|
290
295
|
return {
|
|
291
296
|
messages: prompt,
|
|
292
297
|
...(awsModel.system_as_separate_field && system_message && { system: system_message }),
|
|
293
298
|
[awsModel.max_tokens_param_name]: max_gen_tokens,
|
|
294
299
|
temperature: temperature,
|
|
295
300
|
top_p: top_p,
|
|
301
|
+
...(awsModel.stop_sequences_param_name && stopSequencesValue && {
|
|
302
|
+
[awsModel.stop_sequences_param_name]: Array.isArray(stopSequencesValue) ? stopSequencesValue : [stopSequencesValue]
|
|
303
|
+
}),
|
|
296
304
|
...awsModel.special_request_schema
|
|
297
305
|
};
|
|
298
306
|
}
|
|
@@ -311,6 +319,12 @@ export async function* bedrockWrapper(awsCreds, openaiChatCompletionsCreateObjec
|
|
|
311
319
|
[awsModel.max_tokens_param_name]: max_gen_tokens,
|
|
312
320
|
temperature: temperature,
|
|
313
321
|
top_p: top_p,
|
|
322
|
+
...(() => {
|
|
323
|
+
const stopSequencesValue = stop_sequences || stop;
|
|
324
|
+
return awsModel.stop_sequences_param_name && stopSequencesValue ? {
|
|
325
|
+
[awsModel.stop_sequences_param_name]: Array.isArray(stopSequencesValue) ? stopSequencesValue : [stopSequencesValue]
|
|
326
|
+
} : {};
|
|
327
|
+
})(),
|
|
314
328
|
...awsModel.special_request_schema
|
|
315
329
|
};
|
|
316
330
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bedrock-wrapper",
|
|
3
|
-
"version": "2.4.
|
|
3
|
+
"version": "2.4.2",
|
|
4
4
|
"description": "🪨 Bedrock Wrapper is an npm package that simplifies the integration of existing OpenAI-compatible API objects with AWS Bedrock's serverless inference LLMs.",
|
|
5
5
|
"homepage": "https://www.equilllabs.com/projects/bedrock-wrapper",
|
|
6
6
|
"repository": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"author": "",
|
|
33
33
|
"license": "ISC",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@aws-sdk/client-bedrock-runtime": "^3.
|
|
35
|
+
"@aws-sdk/client-bedrock-runtime": "^3.857.0",
|
|
36
36
|
"dotenv": "^17.2.1",
|
|
37
37
|
"sharp": "^0.34.3"
|
|
38
38
|
},
|