diff --git a/generative-ai/snippets/grounding/groundingPrivateDataBasic.js b/generative-ai/snippets/grounding/groundingPrivateDataBasic.js deleted file mode 100644 index ef0b17c396..0000000000 --- a/generative-ai/snippets/grounding/groundingPrivateDataBasic.js +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2024 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. - -const {GoogleGenAI} = require('@google/genai'); - -/** - * TODO(developer): Update these variables before running the sample. - */ -async function generateContentWithVertexAISearchGrounding( - projectId = 'PROJECT_ID', - location = 'us-central1', - model = 'gemini-2.5-flash', - dataStoreId = 'DATASTORE_ID' -) { - // Initialize client with your Cloud project and location - const client = new GoogleGenAI({ - vertexai: true, - project: projectId, - location: location, - }); - - const tools = [ - { - retrieval: { - vertexAiSearch: { - datastore: `projects/${projectId}/locations/global/collections/default_collection/dataStores/${dataStoreId}`, - }, - }, - }, - ]; - - const result = await client.models.generateContent({ - model: model, - contents: [{role: 'user', parts: [{text: 'Why is the sky blue?'}]}], - config: { - tools: tools, - maxOutputTokens: 256, - safetySettings: [ - { - category: 'HARM_CATEGORY_DANGEROUS_CONTENT', - threshold: 'BLOCK_MEDIUM_AND_ABOVE', - }, - ], - }, - }); - - console.log('Response: ', result.text); - console.log( - 'GroundingMetadata: ', - JSON.stringify(result.candidates[0].groundingMetadata) - ); -} - -generateContentWithVertexAISearchGrounding(...process.argv.slice(2)).catch( - err => { - console.error(err.message); - process.exitCode = 1; - } -); diff --git a/generative-ai/snippets/grounding/groundingPublicDataBasic.js b/generative-ai/snippets/grounding/groundingPublicDataBasic.js deleted file mode 100644 index 167b50ca1a..0000000000 --- a/generative-ai/snippets/grounding/groundingPublicDataBasic.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2024 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. - -const {GoogleGenAI} = require('@google/genai'); - -/** - * TODO(developer): Update these variables before running the sample. - */ -async function generateContentWithGoogleSearchGrounding( - projectId = 'PROJECT_ID', - location = 'us-central1', - model = 'gemini-2.5-flash' -) { - // Initialize client with your Cloud project and location - const client = new GoogleGenAI({ - vertexai: true, - project: projectId, - location: location, - }); - - const googleSearchTool = { - googleSearch: {}, - }; - - const result = await client.models.generateContent({ - model: model, - contents: [{role: 'user', parts: [{text: 'Why is the sky blue?'}]}], - config: { - tools: [googleSearchTool], - maxOutputTokens: 256, - }, - }); - console.log('Response: ', result.text); - console.log( - 'GroundingMetadata is: ', - JSON.stringify(result.candidates[0].groundingMetadata) - ); -} - -generateContentWithGoogleSearchGrounding(...process.argv.slice(2)).catch( - err => { - console.error(err.message); - process.exitCode = 1; - } -); diff --git a/generative-ai/snippets/test/grounding/groundingPrivateDataBasic.test.js b/generative-ai/snippets/test/grounding/groundingPrivateDataBasic.test.js deleted file mode 100644 index 8a84af3a98..0000000000 --- a/generative-ai/snippets/test/grounding/groundingPrivateDataBasic.test.js +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2024 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 cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const projectId = process.env.GOOGLE_SAMPLES_PROJECT; -const location = process.env.LOCATION; -const datastore_id = process.env.DATASTORE_ID; -const model = 'gemini-2.5-flash'; - -describe('Private data grounding', async () => { - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_LOCATION'; - // const model = 'gemini-2.5-flash'; - - it('should ground results in private VertexAI search data', async () => { - const output = execSync( - `node ./grounding/groundingPrivateDataBasic.js ${projectId} ${location} ${model} ${datastore_id}` - ); - assert(output.match(/GroundingMetadata/)); - }); -}); diff --git a/generative-ai/snippets/test/grounding/groundingPublicDataBasic.test.js b/generative-ai/snippets/test/grounding/groundingPublicDataBasic.test.js deleted file mode 100644 index 91f6422dec..0000000000 --- a/generative-ai/snippets/test/grounding/groundingPublicDataBasic.test.js +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2024 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 cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const projectId = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; -const model = 'gemini-2.5-flash'; - -describe('Google search grounding', async () => { - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_LOCATION'; - // const model = 'gemini-2.5-flash'; - - it('should ground results in public search data', async () => { - const output = execSync( - `node ./grounding/groundingPublicDataBasic.js ${projectId} ${location} ${model}` - ); - assert(output.match(/blue/)); - }); -});