Skip to content

Commit 40ad9b8

Browse files
authored
Add a new sample for api version (#352)
1 parent 53bf9b6 commit 40ad9b8

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

samples/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ to comment out cases you do not want to run.
4949
| [search_grounding.js](./search_grounding.js) | Generate with google search grounding |
5050
| [log_prob.js](./log_prob.js) | Generate with log probability for each token |
5151
| [text_generation.js](./text_generation.js) | Generating text |
52+
| [api_version.js](./api_version.js) | Setting api version|

samples/api_version.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @license
3+
* Copyright 2024 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import {
19+
GoogleGenerativeAI,
20+
} from "@google/generative-ai";
21+
22+
async function apiVersion() {
23+
// [START api_version]
24+
// Make sure to include these imports:
25+
// import { GoogleGenerativeAI } from "@google/generative-ai";
26+
const genAI = new GoogleGenerativeAI(process.env.API_KEY);
27+
const model = genAI.getGenerativeModel(
28+
{model: "gemini-1.5-flash"},
29+
{apiVersion: "v1alpha"},
30+
);
31+
32+
const result = await model.generateContent("Why is the sky blue?");
33+
console.log(result.response.text());
34+
// [END api_version]
35+
}
36+
37+
apiVersion();

samples/search_grounding.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ async function searchGrounding() {
4343
},
4444
],
4545
},
46-
{ apiVersion: "v1beta" },
4746
);
4847

4948
const prompt = "What is the price of Google stock today?";

0 commit comments

Comments
 (0)