Skip to content

Commit 8dab294

Browse files
authored
Merge branch 'main' into samples/october-samples
2 parents f4fe3a6 + 2ded410 commit 8dab294

26 files changed

+476
-38
lines changed

genai/count-tokens/counttoken-compute-with-txt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ async function countTokens(
2424
projectId = GOOGLE_CLOUD_PROJECT,
2525
location = GOOGLE_CLOUD_LOCATION
2626
) {
27-
const ai = new GoogleGenAI({
27+
const client = new GoogleGenAI({
2828
vertexai: true,
2929
project: projectId,
3030
location: location,
3131
httpOptions: {apiVersion: 'v1'},
3232
});
3333

34-
const response = await ai.models.computeTokens({
34+
const response = await client.models.computeTokens({
3535
model: 'gemini-2.5-flash',
3636
contents: "What's the longest word in the English language?",
3737
});

genai/count-tokens/counttoken-resp-with-txt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ async function countTokens(
2424
projectId = GOOGLE_CLOUD_PROJECT,
2525
location = GOOGLE_CLOUD_LOCATION
2626
) {
27-
const ai = new GoogleGenAI({
27+
const client = new GoogleGenAI({
2828
vertexai: true,
2929
project: projectId,
3030
location: location,
3131
httpOptions: {apiVersion: 'v1'},
3232
});
3333

34-
const response = await ai.models.generateContent({
34+
const response = await client.models.generateContent({
3535
model: 'gemini-2.5-flash',
3636
contents: 'Why is the sky blue?',
3737
});

genai/count-tokens/counttoken-with-txt-vid.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async function countTokens(
2424
projectId = GOOGLE_CLOUD_PROJECT,
2525
location = GOOGLE_CLOUD_LOCATION
2626
) {
27-
const ai = new GoogleGenAI({
27+
const client = new GoogleGenAI({
2828
vertexai: true,
2929
project: projectId,
3030
location: location,
@@ -37,7 +37,7 @@ async function countTokens(
3737
},
3838
};
3939

40-
const response = await ai.models.countTokens({
40+
const response = await client.models.countTokens({
4141
model: 'gemini-2.5-flash',
4242
contents: [video, 'Provide a description of the video.'],
4343
});

genai/count-tokens/counttoken-with-txt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ async function countTokens(
2424
projectId = GOOGLE_CLOUD_PROJECT,
2525
location = GOOGLE_CLOUD_LOCATION
2626
) {
27-
const ai = new GoogleGenAI({
27+
const client = new GoogleGenAI({
2828
vertexai: true,
2929
project: projectId,
3030
location: location,
3131
});
3232

33-
const response = await ai.models.countTokens({
33+
const response = await client.models.countTokens({
3434
model: 'gemini-2.5-flash',
3535
contents: 'What is the highest mountain in Africa?',
3636
});

genai/image-generation/imggen-mmflash-with-txt.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ async function generateContent(
2626
projectId = GOOGLE_CLOUD_PROJECT,
2727
location = GOOGLE_CLOUD_LOCATION
2828
) {
29-
const ai = new GoogleGenAI({
29+
const client = new GoogleGenAI({
3030
vertexai: true,
3131
project: projectId,
3232
location: location,
3333
});
3434

35-
const response = await ai.models.generateContentStream({
36-
model: 'gemini-2.0-flash-exp',
35+
const response = await client.models.generateContentStream({
36+
model: 'gemini-2.5-flash-image',
3737
contents:
3838
'Generate an image of the Eiffel tower with fireworks in the background.',
3939
config: {

genai/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"test": "c8 mocha -p -j 2 --timeout 2400000 test/*.test.js test/**/*.test.js"
1414
},
1515
"dependencies": {
16-
"@google/genai": "1.12.0",
16+
"@google/genai": "1.20.0",
1717
"axios": "^1.6.2",
1818
"luxon": "^3.7.1",
1919
"supertest": "^7.0.0"
@@ -23,6 +23,7 @@
2323
"chai": "^4.5.0",
2424
"mocha": "^10.0.0",
2525
"sinon": "^18.0.0",
26-
"uuid": "^10.0.0"
26+
"uuid": "^10.0.0",
27+
"proxyquire": "^2.1.3"
2728
}
2829
}

genai/test/imggen-mmflash-with-txt.test.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,20 @@ const {assert} = require('chai');
1818
const {describe, it} = require('mocha');
1919

2020
const projectId = process.env.CAIP_PROJECT_ID;
21+
const location = 'global';
22+
2123
const sample = require('../image-generation/imggen-mmflash-with-txt.js');
2224
const {delay} = require('./util');
2325

2426
describe('imggen-mmflash-with-txt', async () => {
2527
it('should generate images from a text prompt', async function () {
2628
this.timeout(180000);
27-
this.retries(10);
29+
this.retries(5);
2830
await delay(this.test);
29-
const generatedFileNames = await sample.generateContent(projectId);
30-
assert(Array.isArray(generatedFileNames));
31+
const generatedFileNames = await sample.generateContent(
32+
projectId,
33+
location
34+
);
3135
assert(generatedFileNames.length > 0);
3236
});
3337
});
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {describe, it} = require('mocha');
19+
const proxyquire = require('proxyquire').noCallThru();
20+
21+
const projectId = process.env.CAIP_PROJECT_ID;
22+
23+
describe('tuning-job-create', () => {
24+
it('should create tuning job and return job name', async function () {
25+
this.timeout(1000000);
26+
const mockTuningJob = {
27+
name: 'test-tuning-job',
28+
experiment: 'test-experiment',
29+
tunedModel: {
30+
model: 'test-model',
31+
endpoint: 'test-endpoint',
32+
},
33+
};
34+
35+
class MockTunings {
36+
async tune() {
37+
return mockTuningJob;
38+
}
39+
async get() {}
40+
}
41+
42+
class MockGoogleGenAI {
43+
constructor() {
44+
this.tunings = new MockTunings();
45+
}
46+
}
47+
48+
const sample = proxyquire('../tuning/tuning-job-create.js', {
49+
'@google/genai': {GoogleGenAI: MockGoogleGenAI},
50+
});
51+
52+
const response = await sample.createTuningJob(projectId);
53+
54+
assert.strictEqual(response, 'test-tuning-job');
55+
});
56+
});

genai/test/tuning-job-get.test.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {describe, it} = require('mocha');
19+
const proxyquire = require('proxyquire').noCallThru();
20+
21+
const projectId = process.env.GOOGLE_CLOUD_PROJECT || 'test-project';
22+
23+
describe('tuning-job-get', () => {
24+
it('should get tuning job and return job name', async function () {
25+
this.timeout(1000000);
26+
27+
const mockTuningJob = {
28+
name: 'test-tuning-job',
29+
experiment: 'test-experiment',
30+
tunedModel: {
31+
model: 'test-model',
32+
endpoint: 'test-endpoint',
33+
},
34+
};
35+
36+
class MockTunings {
37+
async get({name}) {
38+
if (name !== 'TestJobName')
39+
throw new Error('Unexpected tuning job name');
40+
return mockTuningJob;
41+
}
42+
}
43+
44+
class MockGoogleGenAI {
45+
constructor() {
46+
this.tunings = new MockTunings();
47+
}
48+
}
49+
50+
const sample = proxyquire('../tuning/tuning-job-get.js', {
51+
'@google/genai': {GoogleGenAI: MockGoogleGenAI},
52+
});
53+
54+
const response = await sample.getTuningJob('TestJobName', projectId);
55+
56+
assert.strictEqual(response, 'test-tuning-job');
57+
});
58+
});

genai/test/tuning-job-list.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {describe, it} = require('mocha');
19+
20+
const projectId = process.env.CAIP_PROJECT_ID;
21+
const sample = require('../tuning/tuning-job-list.js');
22+
23+
describe('tuning-job-list', () => {
24+
it('should return tuning job list', async () => {
25+
const output = await sample.listTuningJobs(projectId);
26+
assert(output);
27+
});
28+
});

0 commit comments

Comments
 (0)