File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import {
20
20
GoogleGenerativeAI ,
21
21
} from "@google/generative-ai" ;
22
22
23
+ // `google_search_retrieval` is available in Gemini 1.5
23
24
async function searchGrounding ( ) {
24
25
// [START search_grounding]
25
26
// Make sure to include these imports:
@@ -50,9 +51,36 @@ async function searchGrounding() {
50
51
console . log ( result . response . candidates [ 0 ] . groundingMetadata ) ;
51
52
// [END search_grounding]
52
53
}
54
+
55
+ // `google_search` is available in Gemini 2.0
56
+ async function googleSearch ( ) {
57
+ // [START google_search]
58
+ // Make sure to include these imports:
59
+ // import {
60
+ // GoogleGenerativeAI,
61
+ // } from "@google/generative-ai";
62
+ const genAI = new GoogleGenerativeAI ( process . env . API_KEY ) ;
63
+ const model = genAI . getGenerativeModel (
64
+ {
65
+ model : "gemini-2.0-flash-exp" ,
66
+ tools : [
67
+ {
68
+ googleSearch : { } ,
69
+ } ,
70
+ ] ,
71
+ } ,
72
+ ) ;
73
+
74
+ const prompt = "What is the price of Google stock today?" ;
75
+ const result = await model . generateContent ( prompt ) ;
76
+ console . log ( result . response . candidates [ 0 ] . groundingMetadata ) ;
77
+ // [END google_search]
78
+ }
79
+
53
80
async function runAll ( ) {
54
81
// Comment out or delete any sample cases you don't want to run.
55
82
await searchGrounding ( ) ;
83
+ await googleSearch ( ) ;
56
84
}
57
85
58
86
runAll ( ) ;
You can’t perform that action at this time.
0 commit comments