@@ -113,6 +113,46 @@ describe('Generate Content', () => {
113113 ) . to . be . closeTo ( 4 , TOKEN_COUNT_DELTA ) ;
114114 } ) ;
115115
116+ it ( 'generateContent: google search grounding' , async ( ) => {
117+ const model = getGenerativeModel ( testConfig . ai , {
118+ model : testConfig . model ,
119+ generationConfig : commonGenerationConfig ,
120+ safetySettings : commonSafetySettings ,
121+ tools : [ { googleSearch : { } } ]
122+ } ) ;
123+
124+ const result = await model . generateContent (
125+ 'What is the speed of light in a vaccuum in meters per second?'
126+ ) ;
127+ const response = result . response ;
128+ const trimmedText = response . text ( ) . trim ( ) ;
129+ const groundingMetadata = response . candidates ?. [ 0 ] . groundingMetadata ;
130+ expect ( trimmedText ) . to . contain ( '299,792,458' ) ;
131+ expect ( groundingMetadata ) . to . exist ;
132+ expect ( groundingMetadata ! . searchEntryPoint ?. renderedContent ) . to . contain (
133+ 'div'
134+ ) ;
135+ expect (
136+ groundingMetadata ! . groundingChunks
137+ ) . to . have . length . greaterThanOrEqual ( 1 ) ;
138+ groundingMetadata ! . groundingChunks ! . forEach ( groundingChunk => {
139+ expect ( groundingChunk . web ) . to . exist ;
140+ expect ( groundingChunk . web ! . uri ) . to . exist ;
141+ } ) ;
142+ expect (
143+ groundingMetadata ?. groundingSupports
144+ ) . to . have . length . greaterThanOrEqual ( 1 ) ;
145+ groundingMetadata ! . groundingSupports ! . forEach ( groundingSupport => {
146+ expect (
147+ groundingSupport . groundingChunkIndices
148+ ) . to . have . length . greaterThanOrEqual ( 1 ) ;
149+ expect ( groundingSupport . segment ) . to . exist ;
150+ expect ( groundingSupport . segment ?. endIndex ) . to . exist ;
151+ expect ( groundingSupport . segment ?. text ) . to . exist ;
152+ // Since partIndex and startIndex are commonly 0, they may be omitted from responses.
153+ } ) ;
154+ } ) ;
155+
116156 it ( 'generateContentStream: text input, text output' , async ( ) => {
117157 const model = getGenerativeModel ( testConfig . ai , {
118158 model : testConfig . model ,
0 commit comments