Skip to content

Commit 640a1d2

Browse files
GuinersGuinersmsampathkumargericdong
authored
feat(genai): tools vais sample (#4162)
* adding samples, test, lints * adding samples, test, lints * adding samples, test, lints --------- Co-authored-by: Guiners <[email protected]> Co-authored-by: Sampath Kumar <[email protected]> Co-authored-by: Eric Dong <[email protected]>
1 parent 7f73658 commit 640a1d2

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed
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 {assert} = require('chai');
18+
const {describe, it} = require('mocha');
19+
20+
const projectId = process.env.CAIP_PROJECT_ID;
21+
const sample = require('../tools/tools-vais-with-txt.js');
22+
const location = process.env.GOOGLE_CLOUD_LOCATION || 'global';
23+
const datastore = `projects/${projectId}/locations/global/collections/default_collection/dataStores/grounding-test-datastore`;
24+
25+
describe('tools-vais-with-txt', () => {
26+
it('should generate a function call', async function () {
27+
this.timeout(60000);
28+
const output = await sample.generateContent(datastore, projectId, location);
29+
assert(output.length > 0);
30+
});
31+
});
32+
6;

genai/tools/tools-vais-with-txt.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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_vais_with_txt]
18+
const {GoogleGenAI} = require('@google/genai');
19+
20+
const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
21+
const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global';
22+
// (Developer) put your path Data Store
23+
const DATASTORE =
24+
'projects/cloud-ai-devrel-softserve/locations/global/collections/default_collection/dataStores/example-adk-website-datastore_1755611010401';
25+
26+
async function generateContent(
27+
datastore = DATASTORE,
28+
projectId = GOOGLE_CLOUD_PROJECT,
29+
location = GOOGLE_CLOUD_LOCATION
30+
) {
31+
const client = new GoogleGenAI({
32+
vertexai: true,
33+
project: projectId,
34+
location: location,
35+
httpOptions: {
36+
apiVersion: 'v1',
37+
},
38+
});
39+
40+
const response = await client.models.generateContent({
41+
model: 'gemini-2.5-flash',
42+
contents: "How do I make an appointment to renew my driver's license?",
43+
config: {
44+
tools: [
45+
{
46+
retrieval: {
47+
vertexAiSearch: {
48+
datastore: datastore,
49+
},
50+
},
51+
},
52+
],
53+
},
54+
});
55+
56+
console.debug(response.text);
57+
58+
// Example response:
59+
// '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...'
60+
61+
return response.text;
62+
}
63+
64+
// [END googlegenaisdk_tools_vais_with_txt]
65+
66+
module.exports = {
67+
generateContent,
68+
};

0 commit comments

Comments
 (0)