@@ -21,7 +21,9 @@ import {
2121  GenerationConfig , 
2222  HarmBlockThreshold , 
2323  HarmCategory , 
24+   Language , 
2425  Modality , 
26+   Outcome , 
2527  SafetySetting , 
2628  getGenerativeModel 
2729}  from  '../src' ; 
@@ -188,6 +190,32 @@ describe('Generate Content', () => {
188190        } ) ; 
189191      } ) ; 
190192
193+       it ( 'generateContent: code execution' ,  async  ( )  =>  { 
194+         const  model  =  getGenerativeModel ( testConfig . ai ,  { 
195+           model : testConfig . model , 
196+           generationConfig : commonGenerationConfig , 
197+           safetySettings : commonSafetySettings , 
198+           tools : [ {  codeExecution : { }  } ] 
199+         } ) ; 
200+         const  prompt  = 
201+           'What is the sum of the first 50 prime numbers? '  + 
202+           'Generate and run code for the calculation, and make sure you get all 50.' ; 
203+ 
204+         const  result  =  await  model . generateContent ( prompt ) ; 
205+         const  parts  =  result . response . candidates ?. [ 0 ] . content . parts ; 
206+         expect ( 
207+           parts ?. some ( part  =>  part . executableCode ?. language  ===  Language . PYTHON ) 
208+         ) . to . be . true ; 
209+         expect ( 
210+           parts ?. some ( part  =>  part . codeExecutionResult ?. outcome  ===  Outcome . OK ) 
211+         ) . to . be . true ; 
212+         // Expect these to be truthy (!= null) 
213+         expect ( parts ?. some ( part  =>  part . executableCode ?. code  !=  null ) ) . to . be 
214+           . true ; 
215+         expect ( parts ?. some ( part  =>  part . codeExecutionResult ?. output  !=  null ) ) . to 
216+           . be . true ; 
217+       } ) ; 
218+ 
191219      it ( 'generateContentStream: text input, text output' ,  async  ( )  =>  { 
192220        const  model  =  getGenerativeModel ( testConfig . ai ,  { 
193221          model : testConfig . model , 
0 commit comments