Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions genai/test/tools-vais-with-txt.test.js
Original file line number Diff line number Diff line change
@@ -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;
66 changes: 66 additions & 0 deletions genai/tools/tools-vais-with-txt.js
Original file line number Diff line number Diff line change
@@ -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';
// (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 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,
};
Loading