Skip to content

Commit 7cf04b5

Browse files
authored
Merge branch 'main' into sample/batch-prediction
2 parents e897843 + 081678e commit 7cf04b5

16 files changed

+616
-14
lines changed

genai/test/ctrlgen-with-nullable-schema.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const sample = require('../controlled-generation/ctrlgen-with-nullable-schema.js
2222

2323
describe('ctrlgen-with-nullable-schema', () => {
2424
it('should generate text content using nullable schema', async function () {
25-
this.timeout(10000);
25+
this.timeout(100000);
2626
const output = await sample.generateNullableSchema(projectId);
2727
assert(output.length > 0);
2828
});
24.1 KB
Loading
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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('../tools/tools-code-exec-with-txt-local-img.js');
22+
23+
describe('tools-code-exec-with-txt-local-img', () => {
24+
it('should generate a function definition', async function () {
25+
this.timeout(100000);
26+
const output = await sample.generateAndExecuteMultimodalCode(projectId);
27+
assert(output.length > 0);
28+
});
29+
});

genai/test/tools-code-exec-with-txt.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('tools-code-exec-with-txt', async () => {
2626
this.timeout(180000);
2727
this.retries(4);
2828
await delay(this.test);
29-
const output = await sample.generateContent(projectId);
29+
const output = await sample.generateAndExecuteCode(projectId);
3030
assert(output.length > 0);
3131
});
3232
});

genai/test/tools-func-desc-with-txt.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ describe('tools-func-desc-with-txt', async () => {
2525
this.timeout(180000);
2626
this.retries(4);
2727
await delay(this.test);
28-
await sample.generateContent(projectId);
28+
await sample.generateFunctionDesc(projectId);
2929
});
3030
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 {describe, it} = require('mocha');
18+
19+
const projectId = process.env.CAIP_PROJECT_ID;
20+
const sample = require('../tools/tools-google-maps-coordinates-with-txt');
21+
const {delay} = require('./util');
22+
const {assert} = require('chai');
23+
24+
describe('tools-google-maps-coordinates-with-txt', () => {
25+
it('should use google maps coordinates', async function () {
26+
this.timeout(180000);
27+
this.retries(4);
28+
await delay(this.test);
29+
const output = await sample.generateContent(projectId);
30+
assert(output.length > 0);
31+
});
32+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 {describe, it} = require('mocha');
18+
19+
const projectId = process.env.CAIP_PROJECT_ID;
20+
const sample = require('../tools/tools-google-search-and-urlcontext-with-txt');
21+
const {delay} = require('./util');
22+
const {assert} = require('chai');
23+
24+
describe('tools-google-search-and-urlcontext-with-txt', () => {
25+
it('should create urlcontext and google search', async function () {
26+
this.timeout(180000);
27+
this.retries(4);
28+
await delay(this.test);
29+
const output = await sample.generateContent(projectId);
30+
assert(output.length > 0);
31+
});
32+
});
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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('../tools/tools-google-search-with-txt.js');
22+
23+
describe('tools-google-search-with-txt', () => {
24+
it('should generate answer to a question in prompt using google search', async function () {
25+
this.timeout(10000);
26+
const output = await sample.generateGoogleSearch(projectId);
27+
assert(output.length > 0);
28+
});
29+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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 {describe, it} = require('mocha');
18+
19+
const projectId = process.env.CAIP_PROJECT_ID;
20+
const sample = require('../tools/tools-urlcontext-with-txt');
21+
const {delay} = require('./util');
22+
const {assert} = require('chai');
23+
24+
describe('tools-urlcontext-with-txt', () => {
25+
it('should create urlcontext with txt', async function () {
26+
this.timeout(180000);
27+
this.retries(4);
28+
await delay(this.test);
29+
const output = await sample.generateContent(projectId);
30+
assert(output.length > 0);
31+
});
32+
});
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
// [START googlegenaisdk_tools_exec_with_txt_local_img]
18+
const fs = require('fs').promises;
19+
const path = require('path');
20+
21+
const {GoogleGenAI} = require('@google/genai');
22+
23+
const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
24+
const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global';
25+
26+
async function generateAndExecuteMultimodalCode(
27+
projectId = GOOGLE_CLOUD_PROJECT,
28+
location = GOOGLE_CLOUD_LOCATION
29+
) {
30+
const client = new GoogleGenAI({
31+
vertexai: true,
32+
project: projectId,
33+
location: location,
34+
});
35+
36+
const imagePath = path.join(
37+
__dirname,
38+
'../test/test-data/640px-Monty_open_door.svg.png'
39+
);
40+
const imageBuffer = await fs.readFile(imagePath);
41+
const imageBase64 = imageBuffer.toString('base64');
42+
43+
const prompt = `
44+
Run a simulation of the Monty Hall Problem with 1,000 trials.
45+
Here's how this works as a reminder. In the Monty Hall Problem, you're on a game
46+
show with three doors. Behind one is a car, and behind the others are goats. You
47+
pick a door. The host, who knows what's behind the doors, opens a different door
48+
to reveal a goat. Should you switch to the remaining unopened door?
49+
The answer has always been a little difficult for me to understand when people
50+
solve it with math - so please run a simulation with Python to show me what the
51+
best strategy is.
52+
Thank you!
53+
`;
54+
55+
const contents = [
56+
{
57+
role: 'user',
58+
parts: [
59+
{
60+
inlineData: {
61+
mimeType: 'image/png',
62+
data: imageBase64,
63+
},
64+
},
65+
{
66+
text: prompt,
67+
},
68+
],
69+
},
70+
];
71+
72+
const response = await client.models.generateContent({
73+
model: 'gemini-2.5-flash',
74+
contents: contents,
75+
config: {
76+
tools: [{codeExecution: {}}],
77+
temperature: 0,
78+
},
79+
});
80+
81+
console.debug(response.executableCode);
82+
console.debug(response.codeExecutionResult);
83+
84+
// Example response:
85+
// Win percentage when switching: 65.50%
86+
// Win percentage when not switching: 34.50%
87+
88+
return response.codeExecutionResult;
89+
}
90+
91+
// [END googlegenaisdk_tools_exec_with_txt_local_img]
92+
93+
module.exports = {
94+
generateAndExecuteMultimodalCode,
95+
};

0 commit comments

Comments
 (0)