From ade312bcef6465af4109fe0304e4037118afa8f6 Mon Sep 17 00:00:00 2001 From: Angel Caamal Date: Fri, 26 Jun 2026 19:51:53 +0000 Subject: [PATCH 1/5] feat(genai): introduce new sample and region tag for function calling basic --- .../test/tools-func-calling-basic.test.js | 43 ++++++++++++ genai/tools/tools-func-calling-basic.js | 69 +++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 genai/tools/test/tools-func-calling-basic.test.js create mode 100644 genai/tools/tools-func-calling-basic.js diff --git a/genai/tools/test/tools-func-calling-basic.test.js b/genai/tools/test/tools-func-calling-basic.test.js new file mode 100644 index 00000000000..2b4be9d8c4c --- /dev/null +++ b/genai/tools/test/tools-func-calling-basic.test.js @@ -0,0 +1,43 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +const {assert} = require('chai'); +const {describe, it} = require('mocha'); +const cp = require('child_process'); +const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); + +const projectId = process.env.CAIP_PROJECT_ID; +const location = process.env.GOOGLE_CLOUD_LOCATION; +const model = 'gemini-2.5-flash'; + +describe('tools-func-calling-basic', () => { + /** + * TODO(developer): Uncomment these variables before running the sample.\ + * (Not necessary if passing values as arguments) + */ + // const projectId = 'YOUR_PROJECT_ID'; + // const location = 'YOUR_LOCATION'; + // const model = 'gemini-2.5-flash'; + + it('should define a function and have the model invoke it', async () => { + const output = execSync( + `node ./tools/tools-func-calling-basic.js ${projectId} ${location} ${model}` + ); + + // Assert that the response is what we expect + assert(output.length > 0); + }); +}); diff --git a/genai/tools/tools-func-calling-basic.js b/genai/tools/tools-func-calling-basic.js new file mode 100644 index 00000000000..17993b1305f --- /dev/null +++ b/genai/tools/tools-func-calling-basic.js @@ -0,0 +1,69 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// [START googlegenaisdk_function_calling_basic] +const {GoogleGenAI} = require('@google/genai'); + +const tools = [ + { + functionDeclarations: [ + { + name: 'get_current_weather', + description: 'get weather in a given location', + parameters: { + type: 'OBJECT', + properties: { + location: {type: 'STRING'}, + unit: { + type: 'STRING', + enum: ['celsius', 'fahrenheit'], + }, + }, + required: ['location'], + }, + }, + ], + }, +]; + +/** + * TODO(developer): Update these variables before running the sample. + */ +async function functionCallingBasic( + projectId = 'PROJECT_ID', + location = 'us-central1', + model = 'gemini-2.5-flash' +) { + // Initialize client with your Cloud project and location + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const result = await client.models.generateContent({ + model: model, + contents: 'What is the weather in Boston?', + config: { + tools: tools, + }, + }); + console.log(JSON.stringify(result.functionCalls)); +} +// [END googlegenaisdk_function_calling_basic] + +functionCallingBasic(...process.argv.slice(2)).catch(err => { + console.error(err.message); + process.exitCode = 1; +}); From 0160c0cd44ccf8f19a0059f4577ba4b6ade49f22 Mon Sep 17 00:00:00 2001 From: Angel Caamal Date: Fri, 26 Jun 2026 19:57:16 +0000 Subject: [PATCH 2/5] test(genai): strengthen function calling test assertions --- genai/tools/test/tools-func-calling-basic.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/genai/tools/test/tools-func-calling-basic.test.js b/genai/tools/test/tools-func-calling-basic.test.js index 2b4be9d8c4c..bcc1913ef2c 100644 --- a/genai/tools/test/tools-func-calling-basic.test.js +++ b/genai/tools/test/tools-func-calling-basic.test.js @@ -39,5 +39,6 @@ describe('tools-func-calling-basic', () => { // Assert that the response is what we expect assert(output.length > 0); + assert.include(output, 'get_current_weather'); }); }); From 488caf2662da828f0524b2031368b43aba908168 Mon Sep 17 00:00:00 2001 From: Angel Caamal Date: Fri, 26 Jun 2026 20:05:28 +0000 Subject: [PATCH 3/5] fix(genai): update environment variables in function calling test --- genai/tools/test/tools-func-calling-basic.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/genai/tools/test/tools-func-calling-basic.test.js b/genai/tools/test/tools-func-calling-basic.test.js index bcc1913ef2c..ecaefd4a2cc 100644 --- a/genai/tools/test/tools-func-calling-basic.test.js +++ b/genai/tools/test/tools-func-calling-basic.test.js @@ -19,8 +19,8 @@ const {describe, it} = require('mocha'); const cp = require('child_process'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); -const projectId = process.env.CAIP_PROJECT_ID; -const location = process.env.GOOGLE_CLOUD_LOCATION; +const projectId = process.env.GOOGLE_CLOUD_PROJECT; +const location = process.env.GOOGLE_CLOUD_LOCATION || 'global'; const model = 'gemini-2.5-flash'; describe('tools-func-calling-basic', () => { From d6fec0ebf0b2ed34f0a2464f8be00d5386cf0530 Mon Sep 17 00:00:00 2001 From: Angel Caamal Date: Fri, 26 Jun 2026 20:11:37 +0000 Subject: [PATCH 4/5] fix(genai): correct sample path in function calling test --- genai/tools/test/tools-func-calling-basic.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genai/tools/test/tools-func-calling-basic.test.js b/genai/tools/test/tools-func-calling-basic.test.js index ecaefd4a2cc..b421623eb50 100644 --- a/genai/tools/test/tools-func-calling-basic.test.js +++ b/genai/tools/test/tools-func-calling-basic.test.js @@ -34,7 +34,7 @@ describe('tools-func-calling-basic', () => { it('should define a function and have the model invoke it', async () => { const output = execSync( - `node ./tools/tools-func-calling-basic.js ${projectId} ${location} ${model}` + `node ./tools-func-calling-basic.js ${projectId} ${location} ${model}` ); // Assert that the response is what we expect From 3238af0993fa054c5fb804b1ac83c782241de94a Mon Sep 17 00:00:00 2001 From: Angel Caamal Date: Fri, 26 Jun 2026 21:04:08 +0000 Subject: [PATCH 5/5] fix: update region tag for function calling --- genai/tools/tools-func-calling-basic.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/genai/tools/tools-func-calling-basic.js b/genai/tools/tools-func-calling-basic.js index 17993b1305f..f1991f6d9b6 100644 --- a/genai/tools/tools-func-calling-basic.js +++ b/genai/tools/tools-func-calling-basic.js @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// [START googlegenaisdk_function_calling_basic] +// [START aiplatform_genai_function_calling_basic] const {GoogleGenAI} = require('@google/genai'); const tools = [ @@ -61,7 +61,7 @@ async function functionCallingBasic( }); console.log(JSON.stringify(result.functionCalls)); } -// [END googlegenaisdk_function_calling_basic] +// [END aiplatform_genai_function_calling_basic] functionCallingBasic(...process.argv.slice(2)).catch(err => { console.error(err.message);