@@ -434,10 +434,10 @@ describe('generateContent', () => {
434
434
} ) ;
435
435
const response = result . response ;
436
436
const groundingMetadata = response . candidates [ 0 ] . groundingMetadata ;
437
- expect ( groundingMetadata ) . toBeDefined ( ) ;
437
+ expect ( ! ! groundingMetadata ) . toBeTruthy ( ) ;
438
438
if ( groundingMetadata ) {
439
- expect ( groundingMetadata . groundingAttributions ) . toBeTruthy ( ) ;
440
- expect ( groundingMetadata . webSearchQueries ) . toBeTruthy ( ) ;
439
+ expect ( ! ! groundingMetadata . groundingAttributions ) . toBeTruthy ( ) ;
440
+ expect ( ! ! groundingMetadata . webSearchQueries ) . toBeTruthy ( ) ;
441
441
}
442
442
} ) ;
443
443
it ( 'should return grounding metadata when passed GoogleSearchRetriever in generateContent' , async ( ) => {
@@ -450,10 +450,10 @@ describe('generateContent', () => {
450
450
} ) ;
451
451
const response = result . response ;
452
452
const groundingMetadata = response . candidates [ 0 ] . groundingMetadata ;
453
- expect ( groundingMetadata ) . toBeDefined ( ) ;
453
+ expect ( ! ! groundingMetadata ) . toBeTruthy ( ) ;
454
454
if ( groundingMetadata ) {
455
- expect ( groundingMetadata . groundingAttributions ) . toBeTruthy ( ) ;
456
- expect ( groundingMetadata . webSearchQueries ) . toBeTruthy ( ) ;
455
+ expect ( ! ! groundingMetadata . groundingAttributions ) . toBeTruthy ( ) ;
456
+ expect ( ! ! groundingMetadata . webSearchQueries ) . toBeTruthy ( ) ;
457
457
}
458
458
} ) ;
459
459
it ( 'in preview should return grounding metadata when passed GoogleSearchRetriever in getGenerativeModel' , async ( ) => {
@@ -466,10 +466,10 @@ describe('generateContent', () => {
466
466
} ) ;
467
467
const response = result . response ;
468
468
const groundingMetadata = response . candidates [ 0 ] . groundingMetadata ;
469
- expect ( groundingMetadata ) . toBeDefined ( ) ;
469
+ expect ( ! ! groundingMetadata ) . toBeTruthy ( ) ;
470
470
if ( groundingMetadata ) {
471
- expect ( groundingMetadata . groundingAttributions ) . toBeTruthy ( ) ;
472
- expect ( groundingMetadata . webSearchQueries ) . toBeTruthy ( ) ;
471
+ expect ( ! ! groundingMetadata . groundingAttributions ) . toBeTruthy ( ) ;
472
+ expect ( ! ! groundingMetadata . webSearchQueries ) . toBeTruthy ( ) ;
473
473
}
474
474
} ) ;
475
475
it ( 'in preview should return grounding metadata when passed GoogleSearchRetriever in generateContent' , async ( ) => {
@@ -482,10 +482,10 @@ describe('generateContent', () => {
482
482
} ) ;
483
483
const response = result . response ;
484
484
const groundingMetadata = response . candidates [ 0 ] . groundingMetadata ;
485
- expect ( groundingMetadata ) . toBeDefined ( ) ;
485
+ expect ( ! ! groundingMetadata ) . toBeTruthy ( ) ;
486
486
if ( groundingMetadata ) {
487
- expect ( groundingMetadata . groundingAttributions ) . toBeTruthy ( ) ;
488
- expect ( groundingMetadata . webSearchQueries ) . toBeTruthy ( ) ;
487
+ expect ( ! ! groundingMetadata . groundingAttributions ) . toBeTruthy ( ) ;
488
+ expect ( ! ! groundingMetadata . webSearchQueries ) . toBeTruthy ( ) ;
489
489
}
490
490
} ) ;
491
491
} ) ;
@@ -514,6 +514,68 @@ describe('sendMessage', () => {
514
514
) ;
515
515
expect ( chat . history . length ) . toBe ( 2 ) ;
516
516
} ) ;
517
+ it ( 'should return grounding metadata when passed GoogleSearchRetriever in getGenerativeModel' , async ( ) => {
518
+ const generativeTextModel = vertex_ai . getGenerativeModel ( {
519
+ model : 'gemini-pro' ,
520
+ tools : TOOLS_WITH_GOOGLE_SEARCH_RETRIEVAL ,
521
+ } ) ;
522
+ const chat = generativeTextModel . startChat ( ) ;
523
+ const result = await chat . sendMessage ( 'Why is the sky blue?' ) ;
524
+ const response = result . response ;
525
+ const groundingMetadata = response . candidates [ 0 ] . groundingMetadata ;
526
+ expect ( ! ! groundingMetadata ) . toBeTruthy ( ) ;
527
+ if ( groundingMetadata ) {
528
+ expect ( ! ! groundingMetadata . groundingAttributions ) . toBeTruthy ( ) ;
529
+ expect ( ! ! groundingMetadata . webSearchQueries ) . toBeTruthy ( ) ;
530
+ }
531
+ } ) ;
532
+ it ( 'should return grounding metadata when passed GoogleSearchRetriever in startChat' , async ( ) => {
533
+ const generativeTextModel = vertex_ai . getGenerativeModel ( {
534
+ model : 'gemini-pro' ,
535
+ } ) ;
536
+ const chat = generativeTextModel . startChat ( {
537
+ tools : TOOLS_WITH_GOOGLE_SEARCH_RETRIEVAL ,
538
+ } ) ;
539
+ const result = await chat . sendMessage ( 'Why is the sky blue?' ) ;
540
+ const response = result . response ;
541
+ const groundingMetadata = response . candidates [ 0 ] . groundingMetadata ;
542
+ expect ( ! ! groundingMetadata ) . toBeTruthy ( ) ;
543
+ if ( groundingMetadata ) {
544
+ expect ( ! ! groundingMetadata . groundingAttributions ) . toBeTruthy ( ) ;
545
+ expect ( ! ! groundingMetadata . webSearchQueries ) . toBeTruthy ( ) ;
546
+ }
547
+ } ) ;
548
+ it ( 'in preview should return grounding metadata when passed GoogleSearchRetriever in getGenerativeModel' , async ( ) => {
549
+ const generativeTextModel = vertex_ai . preview . getGenerativeModel ( {
550
+ model : 'gemini-pro' ,
551
+ tools : TOOLS_WITH_GOOGLE_SEARCH_RETRIEVAL ,
552
+ } ) ;
553
+ const chat = generativeTextModel . startChat ( ) ;
554
+ const result = await chat . sendMessage ( 'Why is the sky blue?' ) ;
555
+ const response = result . response ;
556
+ const groundingMetadata = response . candidates [ 0 ] . groundingMetadata ;
557
+ expect ( ! ! groundingMetadata ) . toBeTruthy ( ) ;
558
+ if ( groundingMetadata ) {
559
+ expect ( ! ! groundingMetadata . groundingAttributions ) . toBeTruthy ( ) ;
560
+ expect ( ! ! groundingMetadata . webSearchQueries ) . toBeTruthy ( ) ;
561
+ }
562
+ } ) ;
563
+ it ( 'in preview should return grounding metadata when passed GoogleSearchRetriever in startChat' , async ( ) => {
564
+ const generativeTextModel = vertex_ai . preview . getGenerativeModel ( {
565
+ model : 'gemini-pro' ,
566
+ } ) ;
567
+ const chat = generativeTextModel . startChat ( {
568
+ tools : TOOLS_WITH_GOOGLE_SEARCH_RETRIEVAL ,
569
+ } ) ;
570
+ const result = await chat . sendMessage ( 'Why is the sky blue?' ) ;
571
+ const response = result . response ;
572
+ const groundingMetadata = response . candidates [ 0 ] . groundingMetadata ;
573
+ expect ( ! ! groundingMetadata ) . toBeTruthy ( ) ;
574
+ if ( groundingMetadata ) {
575
+ expect ( ! ! groundingMetadata . groundingAttributions ) . toBeTruthy ( ) ;
576
+ expect ( ! ! groundingMetadata . webSearchQueries ) . toBeTruthy ( ) ;
577
+ }
578
+ } ) ;
517
579
} ) ;
518
580
519
581
describe ( 'sendMessageStream' , ( ) => {
0 commit comments