From 83ca1ff3fc56e20ca2bf054ebea154a0cad3b80f Mon Sep 17 00:00:00 2001 From: Guiners Date: Fri, 22 Aug 2025 10:05:16 +0200 Subject: [PATCH 1/2] adding samples, test, lints --- genai/test/tools-vais-with-txt.test.js | 32 +++++++++++++ genai/tools/tools-vais-with-txt.js | 66 ++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 genai/test/tools-vais-with-txt.test.js create mode 100644 genai/tools/tools-vais-with-txt.js diff --git a/genai/test/tools-vais-with-txt.test.js b/genai/test/tools-vais-with-txt.test.js new file mode 100644 index 0000000000..c0fb529e28 --- /dev/null +++ b/genai/test/tools-vais-with-txt.test.js @@ -0,0 +1,32 @@ +// Copyright 2025 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 projectId = process.env.CAIP_PROJECT_ID; +const sample = require('../tools/tools-vais-with-txt.js'); +const location = process.env.GOOGLE_CLOUD_LOCATION || 'global'; +const datastore = `projects/${projectId}/locations/global/collections/default_collection/dataStores/grounding-test-datastore`; + +describe('tools-vais-with-txt', () => { + it('should generate a function call', async function () { + this.timeout(60000); + const output = await sample.generateContent(datastore, projectId, location); + assert(output.length > 0); + }); +}); +6; diff --git a/genai/tools/tools-vais-with-txt.js b/genai/tools/tools-vais-with-txt.js new file mode 100644 index 0000000000..c4f1eb983d --- /dev/null +++ b/genai/tools/tools-vais-with-txt.js @@ -0,0 +1,66 @@ +// Copyright 2025 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'; + +// [START googlegenaisdk_tools_vais_with_txt] +const {GoogleGenAI} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; +// put your path Data Store +const DATASTORE = + 'projects/cloud-ai-devrel-softserve/locations/global/collections/default_collection/dataStores/example-adk-website-datastore_1755611010401'; + +async function generateContent( + datastore = DATASTORE, + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + httpOptions: { + apiVersion: 'v1', + }, + }); + + const response = await ai.models.generateContent({ + model: 'gemini-2.5-flash', + contents: "How do I make an appointment to renew my driver's license?", + config: { + tools: [ + { + retrieval: { + vertexAiSearch: { + datastore: datastore, + }, + }, + }, + ], + }, + }); + + console.debug(response.text); + + return response.text; +} +// Example response: +// 'The process for making an appointment to renew your driver's license varies depending on your location. To provide you with the most accurate instructions...' +// [END googlegenaisdk_tools_vais_with_txt] + +module.exports = { + generateContent, +}; From bc50eec01ec875337be9ea33a53f215d741979e5 Mon Sep 17 00:00:00 2001 From: Guiners Date: Fri, 22 Aug 2025 10:10:32 +0200 Subject: [PATCH 2/2] adding samples, test, lints --- genai/tools/tools-vais-with-txt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genai/tools/tools-vais-with-txt.js b/genai/tools/tools-vais-with-txt.js index c4f1eb983d..932412fb9e 100644 --- a/genai/tools/tools-vais-with-txt.js +++ b/genai/tools/tools-vais-with-txt.js @@ -19,7 +19,7 @@ const {GoogleGenAI} = require('@google/genai'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -// put your path Data Store +// (Developer) put your path Data Store const DATASTORE = 'projects/cloud-ai-devrel-softserve/locations/global/collections/default_collection/dataStores/example-adk-website-datastore_1755611010401';