@@ -24,6 +24,13 @@ const claude = {
24
24
}
25
25
}
26
26
27
+ const regionClaude = {
28
+ modelId : 'us.anthropic.claude-v1' ,
29
+ body : {
30
+ prompt : '\n\nHuman: yes\n\nAssistant:'
31
+ }
32
+ }
33
+
27
34
const claude35 = {
28
35
modelId : 'anthropic.claude-3-5-sonnet-20240620-v1:0' ,
29
36
body : {
@@ -35,13 +42,30 @@ const claude35 = {
35
42
}
36
43
}
37
44
45
+ const regionClaude35 = {
46
+ modelId : 'us.anthropic.claude-3-5-sonnet-20240620-v1:0' ,
47
+ body : {
48
+ messages : [
49
+ { role : 'user' , content : [ { type : 'text' , text : 'who are' } ] } ,
50
+ { role : 'assistant' , content : [ { type : 'text' , text : 'researching' } ] } ,
51
+ { role : 'user' , content : [ { type : 'text' , text : 'you' } ] }
52
+ ]
53
+ }
54
+ }
38
55
const claude3 = {
39
56
modelId : 'anthropic.claude-3-haiku-20240307-v1:0' ,
40
57
body : {
41
58
messages : [ { role : 'user' , content : 'who are you' } ]
42
59
}
43
60
}
44
61
62
+ const regionClaude3 = {
63
+ modelId : 'us.anthropic.claude-3-haiku-20240307-v1:0' ,
64
+ body : {
65
+ messages : [ { role : 'user' , content : 'who are you' } ]
66
+ }
67
+ }
68
+
45
69
const cohere = {
46
70
modelId : 'cohere.command-text-v14' ,
47
71
body : {
@@ -154,6 +178,17 @@ test('claude minimal command works', async (t) => {
154
178
assert . equal ( cmd . temperature , undefined )
155
179
} )
156
180
181
+ test ( 'region specific claude minimal command works' , async ( t ) => {
182
+ t . nr . updatePayload ( structuredClone ( regionClaude ) )
183
+ const cmd = new BedrockCommand ( t . nr . input )
184
+ assert . equal ( cmd . isClaude ( ) , true )
185
+ assert . equal ( cmd . maxTokens , undefined )
186
+ assert . equal ( cmd . modelId , regionClaude . modelId )
187
+ assert . equal ( cmd . modelType , 'completion' )
188
+ assert . deepEqual ( cmd . prompt , [ { role : 'user' , content : claude . body . prompt } ] )
189
+ assert . equal ( cmd . temperature , undefined )
190
+ } )
191
+
157
192
test ( 'claude complete command works' , async ( t ) => {
158
193
const payload = structuredClone ( claude )
159
194
payload . body . max_tokens_to_sample = 25
@@ -168,6 +203,20 @@ test('claude complete command works', async (t) => {
168
203
assert . equal ( cmd . temperature , payload . body . temperature )
169
204
} )
170
205
206
+ test ( 'region specific claude complete command works' , async ( t ) => {
207
+ const payload = structuredClone ( regionClaude )
208
+ payload . body . max_tokens_to_sample = 25
209
+ payload . body . temperature = 0.5
210
+ t . nr . updatePayload ( payload )
211
+ const cmd = new BedrockCommand ( t . nr . input )
212
+ assert . equal ( cmd . isClaude ( ) , true )
213
+ assert . equal ( cmd . maxTokens , 25 )
214
+ assert . equal ( cmd . modelId , payload . modelId )
215
+ assert . equal ( cmd . modelType , 'completion' )
216
+ assert . deepEqual ( cmd . prompt , [ { role : 'user' , content : payload . body . prompt } ] )
217
+ assert . equal ( cmd . temperature , payload . body . temperature )
218
+ } )
219
+
171
220
test ( 'claude3 minimal command works' , async ( t ) => {
172
221
t . nr . updatePayload ( structuredClone ( claude3 ) )
173
222
const cmd = new BedrockCommand ( t . nr . input )
@@ -179,6 +228,17 @@ test('claude3 minimal command works', async (t) => {
179
228
assert . equal ( cmd . temperature , undefined )
180
229
} )
181
230
231
+ test ( 'region specific claude3 minimal command works' , async ( t ) => {
232
+ t . nr . updatePayload ( structuredClone ( regionClaude3 ) )
233
+ const cmd = new BedrockCommand ( t . nr . input )
234
+ assert . equal ( cmd . isClaude3 ( ) , true )
235
+ assert . equal ( cmd . maxTokens , undefined )
236
+ assert . equal ( cmd . modelId , regionClaude3 . modelId )
237
+ assert . equal ( cmd . modelType , 'completion' )
238
+ assert . deepEqual ( cmd . prompt , claude3 . body . messages )
239
+ assert . equal ( cmd . temperature , undefined )
240
+ } )
241
+
182
242
test ( 'claude3 complete command works' , async ( t ) => {
183
243
const payload = structuredClone ( claude3 )
184
244
payload . body . max_tokens = 25
@@ -193,6 +253,20 @@ test('claude3 complete command works', async (t) => {
193
253
assert . equal ( cmd . temperature , payload . body . temperature )
194
254
} )
195
255
256
+ test ( 'region specific claude3 complete command works' , async ( t ) => {
257
+ const payload = structuredClone ( regionClaude3 )
258
+ payload . body . max_tokens = 25
259
+ payload . body . temperature = 0.5
260
+ t . nr . updatePayload ( payload )
261
+ const cmd = new BedrockCommand ( t . nr . input )
262
+ assert . equal ( cmd . isClaude3 ( ) , true )
263
+ assert . equal ( cmd . maxTokens , 25 )
264
+ assert . equal ( cmd . modelId , payload . modelId )
265
+ assert . equal ( cmd . modelType , 'completion' )
266
+ assert . deepEqual ( cmd . prompt , payload . body . messages )
267
+ assert . equal ( cmd . temperature , payload . body . temperature )
268
+ } )
269
+
196
270
test ( 'claude35 minimal command works with claude 3 api' , async ( t ) => {
197
271
t . nr . updatePayload ( structuredClone ( claude3 ) )
198
272
const cmd = new BedrockCommand ( t . nr . input )
@@ -217,6 +291,19 @@ test('claude35 malformed payload produces reasonable values', async (t) => {
217
291
assert . equal ( cmd . temperature , undefined )
218
292
} )
219
293
294
+ test ( 'region specific claude35 malformed payload produces reasonable values' , async ( t ) => {
295
+ const malformedPayload = structuredClone ( regionClaude35 )
296
+ malformedPayload . body = { }
297
+ t . nr . updatePayload ( malformedPayload )
298
+ const cmd = new BedrockCommand ( t . nr . input )
299
+ assert . equal ( cmd . isClaude3 ( ) , true )
300
+ assert . equal ( cmd . maxTokens , undefined )
301
+ assert . equal ( cmd . modelId , regionClaude35 . modelId )
302
+ assert . equal ( cmd . modelType , 'completion' )
303
+ assert . deepEqual ( cmd . prompt , [ ] )
304
+ assert . equal ( cmd . temperature , undefined )
305
+ } )
306
+
220
307
test ( 'claude35 skips a message that is null in `body.messages`' , async ( t ) => {
221
308
const malformedPayload = structuredClone ( claude35 )
222
309
malformedPayload . body . messages = [ { role : 'user' , content : 'who are you' } , null ]
@@ -226,6 +313,15 @@ test('claude35 skips a message that is null in `body.messages`', async (t) => {
226
313
assert . deepEqual ( cmd . prompt , [ { role : 'user' , content : 'who are you' } ] )
227
314
} )
228
315
316
+ test ( 'region specific claude35 skips a message that is null in `body.messages`' , async ( t ) => {
317
+ const malformedPayload = structuredClone ( regionClaude35 )
318
+ malformedPayload . body . messages = [ { role : 'user' , content : 'who are you' } , null ]
319
+ t . nr . updatePayload ( malformedPayload )
320
+ const cmd = new BedrockCommand ( t . nr . input )
321
+ assert . equal ( cmd . isClaude3 ( ) , true )
322
+ assert . deepEqual ( cmd . prompt , [ { role : 'user' , content : 'who are you' } ] )
323
+ } )
324
+
229
325
test ( 'claude35 handles defaulting prompt to empty array when `body.messages` is null' , async ( t ) => {
230
326
const malformedPayload = structuredClone ( claude35 )
231
327
malformedPayload . body . messages = null
@@ -235,6 +331,15 @@ test('claude35 handles defaulting prompt to empty array when `body.messages` is
235
331
assert . deepEqual ( cmd . prompt , [ ] )
236
332
} )
237
333
334
+ test ( 'region specific claude35 handles defaulting prompt to empty array when `body.messages` is null' , async ( t ) => {
335
+ const malformedPayload = structuredClone ( regionClaude35 )
336
+ malformedPayload . body . messages = null
337
+ t . nr . updatePayload ( malformedPayload )
338
+ const cmd = new BedrockCommand ( t . nr . input )
339
+ assert . equal ( cmd . isClaude3 ( ) , true )
340
+ assert . deepEqual ( cmd . prompt , [ ] )
341
+ } )
342
+
238
343
test ( 'claude35 minimal command works' , async ( t ) => {
239
344
t . nr . updatePayload ( structuredClone ( claude35 ) )
240
345
const cmd = new BedrockCommand ( t . nr . input )
@@ -246,6 +351,17 @@ test('claude35 minimal command works', async (t) => {
246
351
assert . equal ( cmd . temperature , undefined )
247
352
} )
248
353
354
+ test ( 'region specific claude35 minimal command works' , async ( t ) => {
355
+ t . nr . updatePayload ( structuredClone ( regionClaude35 ) )
356
+ const cmd = new BedrockCommand ( t . nr . input )
357
+ assert . equal ( cmd . isClaude3 ( ) , true )
358
+ assert . equal ( cmd . maxTokens , undefined )
359
+ assert . equal ( cmd . modelId , regionClaude35 . modelId )
360
+ assert . equal ( cmd . modelType , 'completion' )
361
+ assert . deepEqual ( cmd . prompt , [ { role : 'user' , content : 'who are' } , { role : 'assistant' , content : 'researching' } , { role : 'user' , content : 'you' } ] )
362
+ assert . equal ( cmd . temperature , undefined )
363
+ } )
364
+
249
365
test ( 'claude35 complete command works' , async ( t ) => {
250
366
const payload = structuredClone ( claude35 )
251
367
payload . body . max_tokens = 25
@@ -260,6 +376,20 @@ test('claude35 complete command works', async (t) => {
260
376
assert . equal ( cmd . temperature , payload . body . temperature )
261
377
} )
262
378
379
+ test ( 'region specific claude35 complete command works' , async ( t ) => {
380
+ const payload = structuredClone ( regionClaude35 )
381
+ payload . body . max_tokens = 25
382
+ payload . body . temperature = 0.5
383
+ t . nr . updatePayload ( payload )
384
+ const cmd = new BedrockCommand ( t . nr . input )
385
+ assert . equal ( cmd . isClaude3 ( ) , true )
386
+ assert . equal ( cmd . maxTokens , 25 )
387
+ assert . equal ( cmd . modelId , payload . modelId )
388
+ assert . equal ( cmd . modelType , 'completion' )
389
+ assert . deepEqual ( cmd . prompt , [ { role : 'user' , content : 'who are' } , { role : 'assistant' , content : 'researching' } , { role : 'user' , content : 'you' } ] )
390
+ assert . equal ( cmd . temperature , payload . body . temperature )
391
+ } )
392
+
263
393
test ( 'cohere minimal command works' , async ( t ) => {
264
394
t . nr . updatePayload ( structuredClone ( cohere ) )
265
395
const cmd = new BedrockCommand ( t . nr . input )
0 commit comments