|
| 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