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..67f8d3f12f --- /dev/null +++ b/genai/tools/tools-vais-with-txt.js @@ -0,0 +1,68 @@ +// 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'; +// (Developer) 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 client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + httpOptions: { + apiVersion: 'v1', + }, + }); + + const response = await client.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); + + // 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...' + + return response.text; +} + +// [END googlegenaisdk_tools_vais_with_txt] + +module.exports = { + generateContent, +};