From b4a03b61beb318fe451494bd405da915fec1c573 Mon Sep 17 00:00:00 2001 From: Angel Caamal Date: Thu, 4 Jun 2026 01:39:24 +0000 Subject: [PATCH 1/2] refactor: migrate batch 2 generative-ai samples to @google/genai --- .../snippets/gemini-all-modalities.js | 38 +++--- .../snippets/gemini-audio-summarization.js | 33 +++--- .../snippets/gemini-audio-transcription.js | 32 ++--- generative-ai/snippets/gemini-pdf.js | 27 +++-- .../snippets/gemini-system-instruction.js | 40 ++++--- generative-ai/snippets/gemini-text-input.js | 25 ++-- generative-ai/snippets/gemini-translate.js | 110 ++++++++---------- generative-ai/snippets/gemini-video-audio.js | 34 +++--- generative-ai/snippets/nonStreamingChat.js | 39 +++---- .../test/gemini-all-modalities.test.js | 7 +- .../test/gemini-audio-summarization.test.js | 5 +- .../test/gemini-audio-transcription.test.js | 5 +- .../snippets/test/gemini-pdf.test.js | 5 +- .../test/gemini-system-instruction.test.js | 7 +- .../snippets/test/gemini-text-input.test.js | 7 +- .../snippets/test/gemini-translate.test.js | 8 +- .../snippets/test/gemini-video-audio.test.js | 7 +- .../snippets/test/nonStreamingChat.test.js | 6 +- 18 files changed, 232 insertions(+), 203 deletions(-) diff --git a/generative-ai/snippets/gemini-all-modalities.js b/generative-ai/snippets/gemini-all-modalities.js index 8297629b20..40a913ca72 100644 --- a/generative-ai/snippets/gemini-all-modalities.js +++ b/generative-ai/snippets/gemini-all-modalities.js @@ -13,30 +13,33 @@ // limitations under the License. // [START generativeaionvertexai_gemini_all_modalities] -const {VertexAI} = require('@google-cloud/vertexai'); +const {GoogleGenAI} = require('@google/genai'); /** * TODO(developer): Update these variables before running the sample. */ -async function analyze_all_modalities(projectId = 'PROJECT_ID') { - const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); - - const generativeModel = vertexAI.getGenerativeModel({ - model: 'gemini-2.0-flash-001', +async function analyze_all_modalities( + projectId = 'PROJECT_ID', + model = 'gemini-2.5-flash' +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: 'us-central1', }); const videoFilePart = { - file_data: { - file_uri: + fileData: { + fileUri: 'gs://cloud-samples-data/generative-ai/video/behind_the_scenes_pixel.mp4', - mime_type: 'video/mp4', + mimeType: 'video/mp4', }, }; const imageFilePart = { - file_data: { - file_uri: + fileData: { + fileUri: 'gs://cloud-samples-data/generative-ai/image/a-man-and-a-dog.png', - mime_type: 'image/png', + mimeType: 'image/png', }, }; @@ -52,13 +55,12 @@ async function analyze_all_modalities(projectId = 'PROJECT_ID') { - What is the context of the moment and what does the narrator say about it?`, }; - const request = { - contents: [{role: 'user', parts: [videoFilePart, imageFilePart, textPart]}], - }; + const response = await client.models.generateContent({ + model: model, + contents: [videoFilePart, imageFilePart, textPart], + }); - const resp = await generativeModel.generateContent(request); - const contentResponse = await resp.response; - console.log(JSON.stringify(contentResponse)); + console.log(response.text); } // [END generativeaionvertexai_gemini_all_modalities] diff --git a/generative-ai/snippets/gemini-audio-summarization.js b/generative-ai/snippets/gemini-audio-summarization.js index b250571f17..067a335954 100644 --- a/generative-ai/snippets/gemini-audio-summarization.js +++ b/generative-ai/snippets/gemini-audio-summarization.js @@ -13,22 +13,24 @@ // limitations under the License. // [START generativeaionvertexai_gemini_audio_summarization] -const {VertexAI} = require('@google-cloud/vertexai'); - +const {GoogleGenAI} = require('@google/genai'); /** * TODO(developer): Update these variables before running the sample. */ -async function summarize_audio(projectId = 'PROJECT_ID') { - const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); - - const generativeModel = vertexAI.getGenerativeModel({ - model: 'gemini-2.0-flash-001', +async function summarize_audio( + projectId = 'PROJECT_ID', + model = 'gemini-2.5-flash' +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: 'us-central1', }); const filePart = { - file_data: { - file_uri: 'gs://cloud-samples-data/generative-ai/audio/pixel.mp3', - mime_type: 'audio/mpeg', + fileData: { + fileUri: 'gs://cloud-samples-data/generative-ai/audio/pixel.mp3', + mimeType: 'audio/mpeg', }, }; const textPart = { @@ -38,13 +40,12 @@ async function summarize_audio(projectId = 'PROJECT_ID') { Do not make up any information that is not part of the audio and do not be verbose.`, }; - const request = { - contents: [{role: 'user', parts: [filePart, textPart]}], - }; + const response = await client.models.generateContent({ + model: model, + contents: [filePart, textPart], + }); - const resp = await generativeModel.generateContent(request); - const contentResponse = await resp.response; - console.log(JSON.stringify(contentResponse)); + console.log(response.text); } // [END generativeaionvertexai_gemini_audio_summarization] diff --git a/generative-ai/snippets/gemini-audio-transcription.js b/generative-ai/snippets/gemini-audio-transcription.js index 3a365fc2c6..568791ea1e 100644 --- a/generative-ai/snippets/gemini-audio-transcription.js +++ b/generative-ai/snippets/gemini-audio-transcription.js @@ -13,22 +13,25 @@ // limitations under the License. // [START generativeaionvertexai_gemini_audio_transcription] -const {VertexAI} = require('@google-cloud/vertexai'); +const {GoogleGenAI} = require('@google/genai'); /** * TODO(developer): Update these variables before running the sample. */ -async function transcript_audio(projectId = 'PROJECT_ID') { - const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); - - const generativeModel = vertexAI.getGenerativeModel({ - model: 'gemini-2.0-flash-001', +async function transcript_audio( + projectId = 'PROJECT_ID', + model = 'gemini-2.5-flash' +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: 'us-central1', }); const filePart = { - file_data: { - file_uri: 'gs://cloud-samples-data/generative-ai/audio/pixel.mp3', - mime_type: 'audio/mpeg', + fileData: { + fileUri: 'gs://cloud-samples-data/generative-ai/audio/pixel.mp3', + mimeType: 'audio/mpeg', }, }; const textPart = { @@ -37,13 +40,12 @@ async function transcript_audio(projectId = 'PROJECT_ID') { Use speaker A, speaker B, etc. to identify speakers.`, }; - const request = { - contents: [{role: 'user', parts: [filePart, textPart]}], - }; + const response = await client.models.generateContent({ + model: model, + contents: [filePart, textPart], + }); - const resp = await generativeModel.generateContent(request); - const contentResponse = await resp.response; - console.log(JSON.stringify(contentResponse)); + console.log(response.text); } // [END generativeaionvertexai_gemini_audio_transcription] diff --git a/generative-ai/snippets/gemini-pdf.js b/generative-ai/snippets/gemini-pdf.js index 314af58d13..bc9c6ecae5 100644 --- a/generative-ai/snippets/gemini-pdf.js +++ b/generative-ai/snippets/gemini-pdf.js @@ -13,16 +13,19 @@ // limitations under the License. // [START generativeaionvertexai_gemini_pdf] -const {VertexAI} = require('@google-cloud/vertexai'); +const {GoogleGenAI} = require('@google/genai'); /** * TODO(developer): Update these variables before running the sample. */ -async function analyze_pdf(projectId = 'PROJECT_ID') { - const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); - - const generativeModel = vertexAI.getGenerativeModel({ - model: 'gemini-2.0-flash-001', +async function analyze_pdf( + projectId = 'PROJECT_ID', + model = 'gemini-2.5-flash' +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: 'us-central1', }); const filePart = { @@ -31,19 +34,19 @@ async function analyze_pdf(projectId = 'PROJECT_ID') { mimeType: 'application/pdf', }, }; + const textPart = { text: ` You are a very professional document summarization specialist. Please summarize the given document.`, }; - const request = { - contents: [{role: 'user', parts: [filePart, textPart]}], - }; + const response = await client.models.generateContent({ + model: model, + contents: [filePart, textPart], + }); - const resp = await generativeModel.generateContent(request); - const contentResponse = await resp.response; - console.log(JSON.stringify(contentResponse)); + console.log(response.text); } // [END generativeaionvertexai_gemini_pdf] diff --git a/generative-ai/snippets/gemini-system-instruction.js b/generative-ai/snippets/gemini-system-instruction.js index 0395034bce..5d9f845b91 100644 --- a/generative-ai/snippets/gemini-system-instruction.js +++ b/generative-ai/snippets/gemini-system-instruction.js @@ -13,22 +13,19 @@ // limitations under the License. // [START generativeaionvertexai_gemini_system_instruction] -const {VertexAI} = require('@google-cloud/vertexai'); +const {GoogleGenAI} = require('@google/genai'); /** * TODO(developer): Update these variables before running the sample. */ -async function set_system_instruction(projectId = 'PROJECT_ID') { - const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); - - const generativeModel = vertexAI.getGenerativeModel({ - model: 'gemini-2.0-flash-001', - systemInstruction: { - parts: [ - {text: 'You are a helpful language translator.'}, - {text: 'Your mission is to translate text in English to French.'}, - ], - }, +async function set_system_instruction( + projectId = 'PROJECT_ID', + model = 'gemini-2.5-flash' +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: 'us-central1', }); const textPart = { @@ -37,13 +34,20 @@ async function set_system_instruction(projectId = 'PROJECT_ID') { Answer:`, }; - const request = { - contents: [{role: 'user', parts: [textPart]}], - }; + const response = await client.models.generateContent({ + model: model, + contents: [textPart], + config: { + systemInstruction: { + parts: [ + {text: 'You are a helpful language translator.'}, + {text: 'Your mission is to translate text in English to French.'}, + ], + }, + }, + }); - const resp = await generativeModel.generateContent(request); - const contentResponse = await resp.response; - console.log(JSON.stringify(contentResponse)); + console.log(response.text); } // [END generativeaionvertexai_gemini_system_instruction] diff --git a/generative-ai/snippets/gemini-text-input.js b/generative-ai/snippets/gemini-text-input.js index 7ce63492c0..44b4905894 100644 --- a/generative-ai/snippets/gemini-text-input.js +++ b/generative-ai/snippets/gemini-text-input.js @@ -13,24 +13,29 @@ // limitations under the License. // [START generativeaionvertexai_gemini_generate_from_text_input] -const {VertexAI} = require('@google-cloud/vertexai'); - +const {GoogleGenAI} = require('@google/genai'); /** * TODO(developer): Update these variables before running the sample. */ -async function generate_from_text_input(projectId = 'PROJECT_ID') { - const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); - - const generativeModel = vertexAI.getGenerativeModel({ - model: 'gemini-2.0-flash-001', +async function generate_from_text_input( + projectId = 'PROJECT_ID', + model = 'gemini-2.5-flash' +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: 'us-central1', }); const prompt = "What's a good name for a flower shop that specializes in selling bouquets of dried flowers?"; - const resp = await generativeModel.generateContent(prompt); - const contentResponse = await resp.response; - console.log(JSON.stringify(contentResponse)); + const response = await client.models.generateContent({ + model: model, + contents: prompt, + }); + + console.log(response.text); } // [END generativeaionvertexai_gemini_generate_from_text_input] diff --git a/generative-ai/snippets/gemini-translate.js b/generative-ai/snippets/gemini-translate.js index 05e03e52ba..6a87019565 100644 --- a/generative-ai/snippets/gemini-translate.js +++ b/generative-ai/snippets/gemini-translate.js @@ -13,20 +13,23 @@ // 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, + }); -async function geminiTranslation(projectId) { - // [START generativeaionvertexai_gemini_translate] - const { - VertexAI, - HarmCategory, - HarmBlockThreshold, - } = require('@google-cloud/vertexai'); - /** - * TODO(developer): Update/uncomment these variables before running the sample. - */ - // projectId = 'your-project-id'; - const location = 'us-central1'; - const modelName = 'gemini-2.0-flash-001'; // The text to be translated. const text = 'Hello! How are you doing today?'; // The language code of the target language. Defaults to "fr" (*French). @@ -34,59 +37,48 @@ async function geminiTranslation(projectId) { // https://cloud.google.com/translate/docs/languages#neural_machine_translation_model const targetLanguageCode = 'fr'; - const generationConfig = { - maxOutputTokens: 2048, - temperature: 0.4, - topP: 1, - topK: 32, - }; - - const safetySettings = [ - { - category: HarmCategory.HARM_CATEGORY_HATE_SPEECH, - threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE, - }, - { - category: HarmCategory.HARM_CATEGORY_DANGEROUS_CONTENT, - threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE, - }, - { - category: HarmCategory.HARM_CATEGORY_SEXUALLY_EXPLICIT, - threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE, - }, - { - category: HarmCategory.HARM_CATEGORY_HARASSMENT, - threshold: HarmBlockThreshold.BLOCK_MEDIUM_AND_ABOVE, - }, - ]; - - const content = `Your mission is to translate text in English to ${targetLanguageCode}`; - - const vertexAI = new VertexAI({project: projectId, location}); - // Instantiate models - const generativeModel = vertexAI.getGenerativeModel({ - model: modelName, - safetySettings, - generationConfig, - systemInstruction: { - parts: [{text: content}], - }, - }); - const textPart = { text: ` User input:${text} Answer:`, }; - const request = { - contents: [{role: 'user', parts: [textPart]}], - }; + 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', + }, + ], + }, + }); - const result = await generativeModel.generateContent(request); - const contentResponse = await result.response; - console.log(JSON.stringify(contentResponse)); - return contentResponse; + console.log(response.text); + return response; // [END generativeaionvertexai_gemini_translate] } diff --git a/generative-ai/snippets/gemini-video-audio.js b/generative-ai/snippets/gemini-video-audio.js index 0b6d7fe123..9df596cb6e 100644 --- a/generative-ai/snippets/gemini-video-audio.js +++ b/generative-ai/snippets/gemini-video-audio.js @@ -13,37 +13,39 @@ // limitations under the License. // [START generativeaionvertexai_gemini_video_with_audio] -const {VertexAI} = require('@google-cloud/vertexai'); - +const {GoogleGenAI} = require('@google/genai'); /** * TODO(developer): Update these variables before running the sample. */ -async function analyze_video_with_audio(projectId = 'PROJECT_ID') { - const vertexAI = new VertexAI({project: projectId, location: 'us-central1'}); - - const generativeModel = vertexAI.getGenerativeModel({ - model: 'gemini-2.0-flash-001', +async function analyze_video_with_audio( + projectId = 'PROJECT_ID', + model = 'gemini-2.5-flash' +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: 'us-central1', }); const filePart = { - file_data: { - file_uri: 'gs://cloud-samples-data/generative-ai/video/pixel8.mp4', - mime_type: 'video/mp4', + fileData: { + fileUri: 'gs://cloud-samples-data/generative-ai/video/pixel8.mp4', + mimeType: 'video/mp4', }, }; + const textPart = { text: ` Provide a description of the video. The description should also contain anything important which people say in the video.`, }; - const request = { - contents: [{role: 'user', parts: [filePart, textPart]}], - }; + const response = await client.models.generateContent({ + model: model, + contents: [filePart, textPart], + }); - const resp = await generativeModel.generateContent(request); - const contentResponse = await resp.response; - console.log(JSON.stringify(contentResponse)); + console.log(response.text); } // [END generativeaionvertexai_gemini_video_with_audio] diff --git a/generative-ai/snippets/nonStreamingChat.js b/generative-ai/snippets/nonStreamingChat.js index 1a6d3ce09b..e216bbc572 100644 --- a/generative-ai/snippets/nonStreamingChat.js +++ b/generative-ai/snippets/nonStreamingChat.js @@ -14,39 +14,38 @@ // [START generativeaionvertexai_gemini_multiturn_chat_nonstreaming] // [START aiplatform_gemini_multiturn_chat_nonstreaming] -const {VertexAI} = require('@google-cloud/vertexai'); - +const {GoogleGenAI} = require('@google/genai'); /** * TODO(developer): Update these variables before running the sample. */ async function createNonStreamingChat( projectId = 'PROJECT_ID', location = 'us-central1', - model = 'gemini-2.0-flash-001' + model = 'gemini-2.5-flash' ) { - // Initialize Vertex with your Cloud project and location - const vertexAI = new VertexAI({project: projectId, location: location}); + // Initialize client with your Cloud project and location + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); - // Instantiate the model - const generativeModel = vertexAI.getGenerativeModel({ + const chat = client.chats.create({ model: model, }); - const chat = generativeModel.startChat({}); - - const result1 = await chat.sendMessage('Hello'); - const response1 = await result1.response; - console.log('Chat response 1: ', JSON.stringify(response1)); + const response1 = await chat.sendMessage({message: 'Hello'}); + console.log('Chat response 1: ', response1.text); - const result2 = await chat.sendMessage( - 'Can you tell me a scientific fun fact?' - ); - const response2 = await result2.response; - console.log('Chat response 2: ', JSON.stringify(response2)); + const response2 = await chat.sendMessage({ + message: 'Can you tell me a scientific fun fact?', + }); + console.log('Chat response 2: ', response2.text); - const result3 = await chat.sendMessage('How can I learn more about that?'); - const response3 = await result3.response; - console.log('Chat response 3: ', JSON.stringify(response3)); + const response3 = await chat.sendMessage({ + message: 'How can I learn more about that?', + }); + console.log('Chat response 3: ', response3.text); } // [END aiplatform_gemini_multiturn_chat_nonstreaming] // [END generativeaionvertexai_gemini_multiturn_chat_nonstreaming] diff --git a/generative-ai/snippets/test/gemini-all-modalities.test.js b/generative-ai/snippets/test/gemini-all-modalities.test.js index 41c41e61eb..2d3752d15e 100644 --- a/generative-ai/snippets/test/gemini-all-modalities.test.js +++ b/generative-ai/snippets/test/gemini-all-modalities.test.js @@ -20,10 +20,13 @@ const cp = require('child_process'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; +const model = 'gemini-2.5-flash'; -describe.skip('Process all modalities', async () => { +describe('Process all modalities', async () => { it('should process all modalities', async () => { - const output = execSync(`node ./gemini-all-modalities.js ${projectId}`); + const output = execSync( + `node ./gemini-all-modalities.js ${projectId} ${model}` + ); assert(output.length > 0); }); diff --git a/generative-ai/snippets/test/gemini-audio-summarization.test.js b/generative-ai/snippets/test/gemini-audio-summarization.test.js index 0c3f82c0a0..6bff587554 100644 --- a/generative-ai/snippets/test/gemini-audio-summarization.test.js +++ b/generative-ai/snippets/test/gemini-audio-summarization.test.js @@ -20,11 +20,12 @@ const cp = require('child_process'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; +const model = 'gemini-2.5-flash'; -describe.skip('Summarize audio', async () => { +describe('Summarize audio', async () => { it('should summarize audio', async () => { const output = execSync( - `node ./gemini-audio-summarization.js ${projectId}` + `node ./gemini-audio-summarization.js ${projectId} ${model}` ); assert(output.length > 0); diff --git a/generative-ai/snippets/test/gemini-audio-transcription.test.js b/generative-ai/snippets/test/gemini-audio-transcription.test.js index 987ed376dc..17499cd9d8 100644 --- a/generative-ai/snippets/test/gemini-audio-transcription.test.js +++ b/generative-ai/snippets/test/gemini-audio-transcription.test.js @@ -20,11 +20,12 @@ const cp = require('child_process'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; +const model = 'gemini-2.5-flash'; -describe.skip('Transcript audio', async () => { +describe('Transcript audio', async () => { it('should transcript audio', async () => { const output = execSync( - `node ./gemini-audio-transcription.js ${projectId}` + `node ./gemini-audio-transcription.js ${projectId} ${model}` ); assert(output.length > 0); diff --git a/generative-ai/snippets/test/gemini-pdf.test.js b/generative-ai/snippets/test/gemini-pdf.test.js index 043538809e..ca97f9609e 100644 --- a/generative-ai/snippets/test/gemini-pdf.test.js +++ b/generative-ai/snippets/test/gemini-pdf.test.js @@ -20,10 +20,11 @@ const cp = require('child_process'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; +const model = 'gemini-2.5-flash'; -describe.skip('Analyze PDF document', async () => { +describe('Analyze PDF document', async () => { it('should analyze PDF document', async () => { - const output = execSync(`node ./gemini-pdf.js ${projectId}`); + const output = execSync(`node ./gemini-pdf.js ${projectId} ${model}`); assert(output.length > 0); }); diff --git a/generative-ai/snippets/test/gemini-system-instruction.test.js b/generative-ai/snippets/test/gemini-system-instruction.test.js index 800c842167..876f06c113 100644 --- a/generative-ai/snippets/test/gemini-system-instruction.test.js +++ b/generative-ai/snippets/test/gemini-system-instruction.test.js @@ -20,10 +20,13 @@ const cp = require('child_process'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; +const model = 'gemini-2.5-flash'; -describe.skip('Set system instruction', async () => { +describe('Set system instruction', async () => { it('should set system instruction', async () => { - const output = execSync(`node ./gemini-system-instruction.js ${projectId}`); + const output = execSync( + `node ./gemini-system-instruction.js ${projectId} ${model}` + ); assert(output.length > 0); }); diff --git a/generative-ai/snippets/test/gemini-text-input.test.js b/generative-ai/snippets/test/gemini-text-input.test.js index 67729be149..80caa063dc 100644 --- a/generative-ai/snippets/test/gemini-text-input.test.js +++ b/generative-ai/snippets/test/gemini-text-input.test.js @@ -20,10 +20,13 @@ const cp = require('child_process'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; +const model = 'gemini-2.5-flash'; -describe.skip('Get store name ideas from text input prompt', async () => { +describe('Get store name ideas from text input prompt', async () => { it('should get store name ideas from text input prompt', async () => { - const output = execSync(`node ./gemini-text-input.js ${projectId}`); + const output = execSync( + `node ./gemini-text-input.js ${projectId} ${model}` + ); assert(output.length > 0); }); diff --git a/generative-ai/snippets/test/gemini-translate.test.js b/generative-ai/snippets/test/gemini-translate.test.js index 337da7da21..15372decc3 100644 --- a/generative-ai/snippets/test/gemini-translate.test.js +++ b/generative-ai/snippets/test/gemini-translate.test.js @@ -20,10 +20,14 @@ 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.skip('Gemini translate', () => { +describe('Gemini translate', () => { it('should translate text', async () => { - const response = execSync(`node ./gemini-translate.js ${projectId}`); + const response = execSync( + `node ./gemini-translate.js ${projectId} ${location} ${model}` + ); assert(JSON.stringify(response).match(/Bonjour/)); }); diff --git a/generative-ai/snippets/test/gemini-video-audio.test.js b/generative-ai/snippets/test/gemini-video-audio.test.js index 697a220e8d..dfa6123a30 100644 --- a/generative-ai/snippets/test/gemini-video-audio.test.js +++ b/generative-ai/snippets/test/gemini-video-audio.test.js @@ -20,10 +20,13 @@ const cp = require('child_process'); const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); const projectId = process.env.CAIP_PROJECT_ID; +const model = 'gemini-2.5-flash'; -describe.skip('Analyze video with audio', async () => { +describe('Analyze video with audio', async () => { it('should analyze video with audio', async () => { - const output = execSync(`node ./gemini-video-audio.js ${projectId}`); + const output = execSync( + `node ./gemini-video-audio.js ${projectId} ${model}` + ); assert(output.length > 0); }); diff --git a/generative-ai/snippets/test/nonStreamingChat.test.js b/generative-ai/snippets/test/nonStreamingChat.test.js index 2a1630bc15..c92d02444c 100644 --- a/generative-ai/snippets/test/nonStreamingChat.test.js +++ b/generative-ai/snippets/test/nonStreamingChat.test.js @@ -21,16 +21,16 @@ 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'; +const model = 'gemini-2.5-flash'; -describe.skip('Generative AI NonStreaming Chat', async () => { +describe('Generative AI NonStreaming Chat', 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.0-flash-001'; + // const model = 'gemini-2.5-flash'; it('should create nonstreaming chat and begin the conversation the same in each instance', async () => { const output = execSync( From 9a805e693e1d84a580df5b4b204da5ad1a7ba92a Mon Sep 17 00:00:00 2001 From: Angel Caamal Date: Thu, 4 Jun 2026 15:27:05 +0000 Subject: [PATCH 2/2] test: add LOCATION fallback and update model to gemini-2.5-flash in translate test --- generative-ai/snippets/test/gemini-translate.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generative-ai/snippets/test/gemini-translate.test.js b/generative-ai/snippets/test/gemini-translate.test.js index 15372decc3..b319a1e7ef 100644 --- a/generative-ai/snippets/test/gemini-translate.test.js +++ b/generative-ai/snippets/test/gemini-translate.test.js @@ -20,7 +20,7 @@ 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 location = process.env.LOCATION || 'us-central1'; const model = 'gemini-2.5-flash'; describe('Gemini translate', () => {