From 1ff48fe3c1830447c70cb2a7c503a3f2a1204bc9 Mon Sep 17 00:00:00 2001 From: Angel Caamal Date: Thu, 16 Jul 2026 18:10:41 +0000 Subject: [PATCH] chore: remove obsolete gemini-translate, nonStreamingContent, and streamContent samples --- generative-ai/snippets/gemini-translate.js | 88 ------------------- generative-ai/snippets/nonStreamingContent.js | 60 ------------- generative-ai/snippets/streamContent.js | 57 ------------ .../snippets/test/gemini-translate.test.js | 34 ------- .../snippets/test/nonStreamingContent.test.js | 43 --------- .../snippets/test/streamContent.test.js | 44 ---------- 6 files changed, 326 deletions(-) delete mode 100644 generative-ai/snippets/gemini-translate.js delete mode 100644 generative-ai/snippets/nonStreamingContent.js delete mode 100644 generative-ai/snippets/streamContent.js delete mode 100644 generative-ai/snippets/test/gemini-translate.test.js delete mode 100644 generative-ai/snippets/test/nonStreamingContent.test.js delete mode 100644 generative-ai/snippets/test/streamContent.test.js diff --git a/generative-ai/snippets/gemini-translate.js b/generative-ai/snippets/gemini-translate.js deleted file mode 100644 index 6a87019565e..00000000000 --- a/generative-ai/snippets/gemini-translate.js +++ /dev/null @@ -1,88 +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'; -// [START generativeaionvertexai_gemini_translate] -const {GoogleGenAI} = require('@google/genai'); - -/** - * TODO(developer): Update these variables before running the sample. - */ -async function geminiTranslation( - projectId = 'PROJECT_ID', - location = 'us-central1', - model = 'gemini-2.5-flash' -) { - const client = new GoogleGenAI({ - vertexai: true, - project: projectId, - location, - }); - - // The text to be translated. - const text = 'Hello! How are you doing today?'; - // The language code of the target language. Defaults to "fr" (*French). - // Available language codes: - // https://cloud.google.com/translate/docs/languages#neural_machine_translation_model - const targetLanguageCode = 'fr'; - - const textPart = { - text: ` - User input:${text} - Answer:`, - }; - - const content = `Your mission is to translate text in English to ${targetLanguageCode}`; - - const response = await client.models.generateContent({ - model: model, - contents: [textPart], - config: { - maxOutputTokens: 2048, - temperature: 0.4, - topP: 1, - topK: 32, - systemInstruction: { - parts: [{text: content}], - }, - safetySettings: [ - { - category: 'HARM_CATEGORY_HATE_SPEECH', - threshold: 'BLOCK_MEDIUM_AND_ABOVE', - }, - { - category: 'HARM_CATEGORY_DANGEROUS_CONTENT', - threshold: 'BLOCK_MEDIUM_AND_ABOVE', - }, - { - category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT', - threshold: 'BLOCK_MEDIUM_AND_ABOVE', - }, - { - category: 'HARM_CATEGORY_HARASSMENT', - threshold: 'BLOCK_MEDIUM_AND_ABOVE', - }, - ], - }, - }); - - console.log(response.text); - return response; - // [END generativeaionvertexai_gemini_translate] -} - -geminiTranslation(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/nonStreamingContent.js b/generative-ai/snippets/nonStreamingContent.js deleted file mode 100644 index 71c6a678725..00000000000 --- a/generative-ai/snippets/nonStreamingContent.js +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2023 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. - -// [START generativeaionvertexai_gemini_content_nonstreaming] -// [START aiplatform_gemini_content_nonstreaming] -const {VertexAI} = require('@google-cloud/vertexai'); - -/** - * TODO(developer): Update these variables before running the sample. - */ -async function createNonStreamingContent( - projectId = 'PROJECT_ID', - location = 'us-central1', - model = 'gemini-2.0-flash-001' -) { - // Initialize Vertex with your Cloud project and location - const vertexAI = new VertexAI({project: projectId, location: location}); - - // Instantiate the model - const generativeModel = vertexAI.getGenerativeModel({ - model: model, - }); - - const request = { - contents: [ - { - role: 'user', - parts: [ - { - text: 'Write a story about a magic backpack.', - }, - ], - }, - ], - }; - - console.log(JSON.stringify(request)); - - const result = await generativeModel.generateContent(request); - - console.log(result.response.text); -} -// [END aiplatform_gemini_content_nonstreaming] -// [END generativeaionvertexai_gemini_content_nonstreaming] - -createNonStreamingContent(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/streamContent.js b/generative-ai/snippets/streamContent.js deleted file mode 100644 index 54e34a9c124..00000000000 --- a/generative-ai/snippets/streamContent.js +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2023 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. - -// [START generativeaionvertexai_gemini_content] -// [START aiplatform_gemini_content] -const {VertexAI} = require('@google-cloud/vertexai'); - -/** - * TODO(developer): Update these variables before running the sample. - */ -async function createStreamContent( - projectId = 'PROJECT_ID', - location = 'us-central1', - model = 'gemini-2.0-flash-001' -) { - // Initialize Vertex with your Cloud project and location - const vertexAI = new VertexAI({project: projectId, location: location}); - - // Instantiate the model - const generativeModel = vertexAI.getGenerativeModel({ - model: model, - }); - - const request = { - contents: [{role: 'user', parts: [{text: 'What is Node.js?'}]}], - }; - - console.log('Prompt:'); - console.log(request.contents[0].parts[0].text); - console.log('Streaming Response Text:'); - - // Create the response stream - const responseStream = await generativeModel.generateContentStream(request); - - // Log the text response as it streams - for await (const item of responseStream.stream) { - process.stdout.write(item.candidates[0].content.parts[0].text); - } -} -// [END aiplatform_gemini_content] -// [END generativeaionvertexai_gemini_content] - -createStreamContent(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/test/gemini-translate.test.js b/generative-ai/snippets/test/gemini-translate.test.js deleted file mode 100644 index b319a1e7ef9..00000000000 --- a/generative-ai/snippets/test/gemini-translate.test.js +++ /dev/null @@ -1,34 +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('node:assert/strict'); -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 || 'us-central1'; -const model = 'gemini-2.5-flash'; - -describe('Gemini translate', () => { - it('should translate text', async () => { - const response = execSync( - `node ./gemini-translate.js ${projectId} ${location} ${model}` - ); - - assert(JSON.stringify(response).match(/Bonjour/)); - }); -}); diff --git a/generative-ai/snippets/test/nonStreamingContent.test.js b/generative-ai/snippets/test/nonStreamingContent.test.js deleted file mode 100644 index bb7c7f75175..00000000000 --- a/generative-ai/snippets/test/nonStreamingContent.test.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2023 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.0-flash-001'; - -describe.skip('Generative AI NonStreaming Content', () => { - /** - * 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.0-flash-001'; - - it('should create nonstreaming content', async () => { - const output = execSync( - `node ./nonStreamingContent.js ${projectId} ${location} ${model}` - ); - - // Assert that the correct prompt was issued - assert(output.match(/Write a story about a magic backpack/)); - }); -}); diff --git a/generative-ai/snippets/test/streamContent.test.js b/generative-ai/snippets/test/streamContent.test.js deleted file mode 100644 index 99fcbf60ae4..00000000000 --- a/generative-ai/snippets/test/streamContent.test.js +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2023 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.0-flash-001'; - -describe.skip('Generative AI Stream Content', () => { - /** - * 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.0-flash-001'; - - it('should create stream content', async () => { - const output = execSync( - `node ./streamContent.js ${projectId} ${location} ${model}` - ); - // Ensure that the beginning of the conversation is consistent - assert(output.match(/Prompt:/)); - assert(output.match(/What is Node.js/)); - assert(output.match(/Streaming Response Text:/)); - }); -});