Skip to content

Commit 6947b01

Browse files
authored
Merge branch 'main' into chore/update-uuid-package
2 parents b745bf3 + efc8d2f commit 6947b01

67 files changed

Lines changed: 1426 additions & 557 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

appengine/storage/flexible/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@google-cloud/storage": "^7.0.0",
1313
"express": "^4.18.2",
14-
"multer": "^1.4.5-lts.1",
14+
"multer": "^2.1.1",
1515
"pug": "^3.0.2"
1616
},
1717
"devDependencies": {

appengine/storage/flexible_nodejs16_and_earlier/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@google-cloud/storage": "^7.0.0",
1313
"express": "^4.18.2",
14-
"multer": "^1.4.5-lts.1",
14+
"multer": "^2.1.1",
1515
"pug": "^3.0.2"
1616
},
1717
"devDependencies": {

appengine/storage/standard/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"dependencies": {
1212
"@google-cloud/storage": "^7.0.0",
1313
"express": "^4.18.2",
14-
"multer": "^1.4.5-lts.1",
14+
"multer": "^2.1.1",
1515
"pug": "^3.0.2"
1616
},
1717
"devDependencies": {

generative-ai/snippets/count-tokens/countTokens.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,42 @@
1313
// limitations under the License.
1414

1515
// [START generativeaionvertexai_gemini_token_count]
16-
const {VertexAI} = require('@google-cloud/vertexai');
16+
const {GoogleGenAI} = require('@google/genai');
1717

1818
/**
1919
* TODO(developer): Update these variables before running the sample.
2020
*/
2121
async function countTokens(
2222
projectId = 'PROJECT_ID',
2323
location = 'us-central1',
24-
model = 'gemini-2.0-flash-001'
24+
model = 'gemini-2.5-flash'
2525
) {
26-
// Initialize Vertex with your Cloud project and location
27-
const vertexAI = new VertexAI({project: projectId, location: location});
28-
29-
// Instantiate the model
30-
const generativeModel = vertexAI.getGenerativeModel({
31-
model: model,
26+
// Initialize the client with your Cloud project and location
27+
const client = new GoogleGenAI({
28+
vertexai: true,
29+
project: projectId,
30+
location: location,
3231
});
3332

34-
const req = {
35-
contents: [{role: 'user', parts: [{text: 'How are you doing today?'}]}],
36-
};
33+
const contents = [
34+
{role: 'user', parts: [{text: 'How are you doing today?'}]},
35+
];
3736

3837
// Prompt tokens count
39-
const countTokensResp = await generativeModel.countTokens(req);
38+
const countTokensResp = await client.models.countTokens({
39+
model: model,
40+
contents: contents,
41+
});
4042
console.log('Prompt tokens count: ', countTokensResp);
4143

4244
// Send text to gemini
43-
const result = await generativeModel.generateContent(req);
45+
const result = await client.models.generateContent({
46+
model: model,
47+
contents: contents,
48+
});
4449

4550
// Response tokens count
46-
const usageMetadata = result.response.usageMetadata;
51+
const usageMetadata = result.usageMetadata;
4752
console.log('Response tokens count: ', usageMetadata);
4853
}
4954
// [END generativeaionvertexai_gemini_token_count]

generative-ai/snippets/count-tokens/countTokensAdvanced.js

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,51 @@
1313
// limitations under the License.
1414

1515
// [START generativeaionvertexai_gemini_token_count_advanced]
16-
const {VertexAI} = require('@google-cloud/vertexai');
17-
16+
const {GoogleGenAI} = require('@google/genai');
1817
/**
1918
* TODO(developer): Update these variables before running the sample.
2019
*/
2120
async function countTokens(
2221
projectId = 'PROJECT_ID',
2322
location = 'us-central1',
24-
model = 'gemini-2.0-flash-001'
23+
model = 'gemini-2.5-flash'
2524
) {
26-
// Initialize Vertex with your Cloud project and location
27-
const vertexAI = new VertexAI({project: projectId, location: location});
28-
29-
// Instantiate the model
30-
const generativeModel = vertexAI.getGenerativeModel({
31-
model: model,
25+
// Initialize client with your Cloud project and location
26+
const client = new GoogleGenAI({
27+
vertexai: true,
28+
project: projectId,
29+
location: location,
3230
});
3331

34-
const req = {
35-
contents: [
36-
{
37-
role: 'user',
38-
parts: [
39-
{
40-
file_data: {
41-
file_uri:
42-
'gs://cloud-samples-data/generative-ai/video/pixel8.mp4',
43-
mime_type: 'video/mp4',
44-
},
32+
const contents = [
33+
{
34+
role: 'user',
35+
parts: [
36+
{
37+
fileData: {
38+
fileUri: 'gs://cloud-samples-data/generative-ai/video/pixel8.mp4',
39+
mimeType: 'video/mp4',
4540
},
46-
{text: 'Provide a description of the video.'},
47-
],
48-
},
49-
],
50-
};
41+
},
42+
{text: 'Provide a description of the video.'},
43+
],
44+
},
45+
];
46+
47+
const countTokensResp = await client.models.countTokens({
48+
model: model,
49+
contents: contents,
50+
});
5151

52-
const countTokensResp = await generativeModel.countTokens(req);
5352
console.log('Prompt Token Count:', countTokensResp.totalTokens);
54-
console.log(
55-
'Prompt Character Count:',
56-
countTokensResp.totalBillableCharacters
57-
);
5853

59-
// Sent text to Gemini
60-
const result = await generativeModel.generateContent(req);
61-
const usageMetadata = result.response.usageMetadata;
54+
// Send text to Gemini
55+
const result = await client.models.generateContent({
56+
model: model,
57+
contents: contents,
58+
});
59+
60+
const usageMetadata = result.usageMetadata;
6261

6362
console.log('Prompt Token Count:', usageMetadata.promptTokenCount);
6463
console.log('Candidates Token Count:', usageMetadata.candidatesTokenCount);

generative-ai/snippets/function-calling/functionCallingAdvanced.js

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,32 +13,28 @@
1313
// limitations under the License.
1414

1515
// [START generativeaionvertexai_function_calling_advanced]
16-
const {
17-
VertexAI,
18-
FunctionDeclarationSchemaType,
19-
} = require('@google-cloud/vertexai');
16+
const {GoogleGenAI} = require('@google/genai');
2017

21-
const functionDeclarations = [
18+
const tools = [
2219
{
23-
function_declarations: [
20+
functionDeclarations: [
2421
{
2522
name: 'get_product_sku',
26-
description:
27-
'Get the available inventory for a Google products, e.g: Pixel phones, Pixel Watches, Google Home etc',
23+
description: 'Get the available inventory for Google products',
2824
parameters: {
29-
type: FunctionDeclarationSchemaType.OBJECT,
25+
type: 'OBJECT',
3026
properties: {
31-
productName: {type: FunctionDeclarationSchemaType.STRING},
27+
productName: {type: 'STRING'},
3228
},
3329
},
3430
},
3531
{
3632
name: 'get_store_location',
3733
description: 'Get the location of the closest store',
3834
parameters: {
39-
type: FunctionDeclarationSchemaType.OBJECT,
35+
type: 'OBJECT',
4036
properties: {
41-
location: {type: FunctionDeclarationSchemaType.STRING},
37+
location: {type: 'STRING'},
4238
},
4339
},
4440
},
@@ -47,49 +43,39 @@ const functionDeclarations = [
4743
];
4844

4945
const toolConfig = {
50-
function_calling_config: {
46+
functionCallingConfig: {
5147
mode: 'ANY',
52-
allowed_function_names: ['get_product_sku'],
48+
allowedFunctionNames: ['get_product_sku'],
5349
},
5450
};
5551

56-
const generationConfig = {
57-
temperature: 0.95,
58-
topP: 1.0,
59-
maxOutputTokens: 8192,
60-
};
61-
6252
/**
6353
* TODO(developer): Update these variables before running the sample.
6454
*/
6555
async function functionCallingAdvanced(
6656
projectId = 'PROJECT_ID',
6757
location = 'us-central1',
68-
model = 'gemini-2.0-flash-001'
58+
model = 'gemini-2.5-flash'
6959
) {
70-
// Initialize Vertex with your Cloud project and location
71-
const vertexAI = new VertexAI({project: projectId, location: location});
60+
// Initialize client with your Cloud project and location
61+
const client = new GoogleGenAI({
62+
vertexai: true,
63+
project: projectId,
64+
location: location,
65+
});
7266

73-
// Instantiate the model
74-
const generativeModel = vertexAI.preview.getGenerativeModel({
67+
const result = await client.models.generateContent({
7568
model: model,
69+
contents: 'Do you have the White Pixel 8 Pro 128GB in stock in the US?',
70+
config: {
71+
tools: tools,
72+
toolConfig: toolConfig,
73+
temperature: 0.95,
74+
topP: 1.0,
75+
maxOutputTokens: 8192,
76+
},
7677
});
77-
78-
const request = {
79-
contents: [
80-
{
81-
role: 'user',
82-
parts: [
83-
{text: 'Do you have the White Pixel 8 Pro 128GB in stock in the US?'},
84-
],
85-
},
86-
],
87-
tools: functionDeclarations,
88-
tool_config: toolConfig,
89-
generation_config: generationConfig,
90-
};
91-
const result = await generativeModel.generateContent(request);
92-
console.log(JSON.stringify(result.response.candidates[0].content));
78+
console.log(JSON.stringify(result.functionCalls));
9379
}
9480
// [END generativeaionvertexai_function_calling_advanced]
9581

generative-ai/snippets/function-calling/functionCallingBasic.js

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,20 @@
1313
// limitations under the License.
1414

1515
// [START generativeaionvertexai_function_calling_basic]
16-
const {
17-
VertexAI,
18-
FunctionDeclarationSchemaType,
19-
} = require('@google-cloud/vertexai');
16+
const {GoogleGenAI} = require('@google/genai');
2017

21-
const functionDeclarations = [
18+
const tools = [
2219
{
23-
function_declarations: [
20+
functionDeclarations: [
2421
{
2522
name: 'get_current_weather',
2623
description: 'get weather in a given location',
2724
parameters: {
28-
type: FunctionDeclarationSchemaType.OBJECT,
25+
type: 'OBJECT',
2926
properties: {
30-
location: {type: FunctionDeclarationSchemaType.STRING},
27+
location: {type: 'STRING'},
3128
unit: {
32-
type: FunctionDeclarationSchemaType.STRING,
29+
type: 'STRING',
3330
enum: ['celsius', 'fahrenheit'],
3431
},
3532
},
@@ -46,24 +43,23 @@ const functionDeclarations = [
4643
async function functionCallingBasic(
4744
projectId = 'PROJECT_ID',
4845
location = 'us-central1',
49-
model = 'gemini-2.0-flash-001'
46+
model = 'gemini-2.5-flash'
5047
) {
51-
// Initialize Vertex with your Cloud project and location
52-
const vertexAI = new VertexAI({project: projectId, location: location});
48+
// Initialize client with your Cloud project and location
49+
const client = new GoogleGenAI({
50+
vertexai: true,
51+
project: projectId,
52+
location: location,
53+
});
5354

54-
// Instantiate the model
55-
const generativeModel = vertexAI.preview.getGenerativeModel({
55+
const result = await client.models.generateContent({
5656
model: model,
57+
contents: 'What is the weather in Boston?',
58+
config: {
59+
tools: tools,
60+
},
5761
});
58-
59-
const request = {
60-
contents: [
61-
{role: 'user', parts: [{text: 'What is the weather in Boston?'}]},
62-
],
63-
tools: functionDeclarations,
64-
};
65-
const result = await generativeModel.generateContent(request);
66-
console.log(JSON.stringify(result.response.candidates[0].content));
62+
console.log(JSON.stringify(result.functionCalls));
6763
}
6864
// [END generativeaionvertexai_function_calling_basic]
6965

0 commit comments

Comments
 (0)