@@ -498,50 +498,61 @@ describe("tool_choice works for supported models", () => {
498
498
) ;
499
499
} ) ;
500
500
501
- it ( "should bind tool_choice when using WSO with supported models" , async ( ) => {
502
- // Claude 3 should NOT throw is using WSO & it should have `tool_choice` bound.
503
- const claude3Model = new ChatBedrockConverse ( {
504
- ...baseConstructorArgs ,
505
- model : "anthropic.claude-3-5-sonnet-20240620-v1:0" ,
506
- // We are not passing the `supportsToolChoiceValues` arg here as
507
- // it should be inferred from the model name.
508
- } ) ;
509
- const claude3ModelWSO = claude3Model . withStructuredOutput ( tool . schema , {
510
- name : tool . name ,
511
- } ) ;
512
- expect ( claude3ModelWSO ) . toBeDefined ( ) ;
513
- const claude3ModelWSOAsJSON = claude3ModelWSO . toJSON ( ) ;
514
- if ( ! ( "kwargs" in claude3ModelWSOAsJSON ) ) {
515
- throw new Error ( "kwargs not found in claude3ModelWSOAsJSON" ) ;
501
+ it . each ( [
502
+ "anthropic.claude-3-5-sonnet-20240620-v1:0" ,
503
+ "anthropic.claude-sonnet-4-20250514-v1:0" ,
504
+ ] ) (
505
+ "should bind tool_choice when using WSO with model that supports tool choice: %s" ,
506
+ ( model ) => {
507
+ // Claude 3 should NOT throw is using WSO & it should have `tool_choice` bound.
508
+ const claude3Model = new ChatBedrockConverse ( {
509
+ ...baseConstructorArgs ,
510
+ model,
511
+ // We are not passing the `supportsToolChoiceValues` arg here as
512
+ // it should be inferred from the model name.
513
+ } ) ;
514
+ const claude3ModelWSO = claude3Model . withStructuredOutput ( tool . schema , {
515
+ name : tool . name ,
516
+ } ) ;
517
+ expect ( claude3ModelWSO ) . toBeDefined ( ) ;
518
+ const claude3ModelWSOAsJSON = claude3ModelWSO . toJSON ( ) ;
519
+ if ( ! ( "kwargs" in claude3ModelWSOAsJSON ) ) {
520
+ throw new Error ( "kwargs not found in claude3ModelWSOAsJSON" ) ;
521
+ }
522
+ expect ( claude3ModelWSOAsJSON . kwargs . bound . first . config ) . toHaveProperty (
523
+ "tool_choice"
524
+ ) ;
525
+ expect ( claude3ModelWSOAsJSON . kwargs . bound . first . config . tool_choice ) . toBe (
526
+ tool . name
527
+ ) ;
516
528
}
517
- expect ( claude3ModelWSOAsJSON . kwargs . bound . first . config ) . toHaveProperty (
518
- "tool_choice"
519
- ) ;
520
- expect ( claude3ModelWSOAsJSON . kwargs . bound . first . config . tool_choice ) . toBe (
521
- tool . name
522
- ) ;
529
+ ) ;
523
530
524
- // Mistral (not mistral large) should NOT throw is using WSO
525
- const mistralModel = new ChatBedrockConverse ( {
526
- ...baseConstructorArgs ,
527
- model : "mistral.mistral-large-2407-v1:0" ,
528
- // We are not passing the `supportsToolChoiceValues` arg here as
529
- // it should be inferred from the model name.
530
- } ) ;
531
- const mistralModelWSO = mistralModel . withStructuredOutput ( tool . schema , {
532
- name : tool . name ,
533
- } ) ;
534
- expect ( mistralModelWSO ) . toBeDefined ( ) ;
535
- const mistralModelWSOAsJSON = mistralModelWSO . toJSON ( ) ;
536
- if ( ! ( "kwargs" in mistralModelWSOAsJSON ) ) {
537
- throw new Error ( "kwargs not found in mistralModelWSOAsJSON" ) ;
531
+ it . each ( [ "mistral.mistral-large-2407-v1:0" ] ) (
532
+ "should bind tool_choice when using WSO with model that doesn't support tool choice: %s" ,
533
+ ( model ) => {
534
+ // Mistral (not mistral large) should NOT throw is using WSO
535
+ const mistralModel = new ChatBedrockConverse ( {
536
+ ...baseConstructorArgs ,
537
+ model,
538
+ // We are not passing the `supportsToolChoiceValues` arg here as
539
+ // it should be inferred from the model name.
540
+ } ) ;
541
+ const mistralModelWSO = mistralModel . withStructuredOutput ( tool . schema , {
542
+ name : tool . name ,
543
+ } ) ;
544
+ expect ( mistralModelWSO ) . toBeDefined ( ) ;
545
+ const mistralModelWSOAsJSON = mistralModelWSO . toJSON ( ) ;
546
+ if ( ! ( "kwargs" in mistralModelWSOAsJSON ) ) {
547
+ throw new Error ( "kwargs not found in mistralModelWSOAsJSON" ) ;
548
+ }
549
+ expect ( mistralModelWSOAsJSON . kwargs . bound . first . config ) . toHaveProperty (
550
+ "tool_choice"
551
+ ) ;
552
+ // Mistral large only supports "auto" and "any" for tool_choice, not the actual tool name
553
+ expect ( mistralModelWSOAsJSON . kwargs . bound . first . config . tool_choice ) . toBe (
554
+ "any"
555
+ ) ;
538
556
}
539
- expect ( mistralModelWSOAsJSON . kwargs . bound . first . config ) . toHaveProperty (
540
- "tool_choice"
541
- ) ;
542
- // Mistral large only supports "auto" and "any" for tool_choice, not the actual tool name
543
- expect ( mistralModelWSOAsJSON . kwargs . bound . first . config . tool_choice ) . toBe (
544
- "any"
545
- ) ;
546
- } ) ;
557
+ ) ;
547
558
} ) ;
0 commit comments