From 673be55bef69320497f48c5fe71ee546ef821dc1 Mon Sep 17 00:00:00 2001 From: Angel Caamal Date: Fri, 24 Jul 2026 17:57:07 +0000 Subject: [PATCH] chore(generative-ai): remove obsolete inference samples --- generative-ai/snippets/gemini-video-audio.js | 53 --------------- .../inference/nonStreamMultiModalityBasic.js | 62 ----------------- .../snippets/inference/nonStreamTextBasic.js | 56 --------------- .../inference/streamMultiModalityBasic.js | 68 ------------------- .../snippets/inference/streamTextBasic.js | 58 ---------------- .../snippets/streamMultipartContent.js | 68 ------------------- .../snippets/test/gemini-video-audio.test.js | 33 --------- .../nonStreamMultiModalityBasic.test.js | 33 --------- .../test/inference/nonStreamTextBasic.test.js | 35 ---------- .../streamMultiModalityBasic.test.js | 33 --------- .../test/inference/streamTextBasic.test.js | 33 --------- .../test/streamMultipartContent.test.js | 49 ------------- 12 files changed, 581 deletions(-) delete mode 100644 generative-ai/snippets/gemini-video-audio.js delete mode 100644 generative-ai/snippets/inference/nonStreamMultiModalityBasic.js delete mode 100644 generative-ai/snippets/inference/nonStreamTextBasic.js delete mode 100644 generative-ai/snippets/inference/streamMultiModalityBasic.js delete mode 100644 generative-ai/snippets/inference/streamTextBasic.js delete mode 100644 generative-ai/snippets/streamMultipartContent.js delete mode 100644 generative-ai/snippets/test/gemini-video-audio.test.js delete mode 100644 generative-ai/snippets/test/inference/nonStreamMultiModalityBasic.test.js delete mode 100644 generative-ai/snippets/test/inference/nonStreamTextBasic.test.js delete mode 100644 generative-ai/snippets/test/inference/streamMultiModalityBasic.test.js delete mode 100644 generative-ai/snippets/test/inference/streamTextBasic.test.js delete mode 100644 generative-ai/snippets/test/streamMultipartContent.test.js diff --git a/generative-ai/snippets/gemini-video-audio.js b/generative-ai/snippets/gemini-video-audio.js deleted file mode 100644 index 8d7b135655..0000000000 --- a/generative-ai/snippets/gemini-video-audio.js +++ /dev/null @@ -1,53 +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 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 = { - 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 response = await client.models.generateContent({ - model: model, - contents: [filePart, textPart], - }); - - console.log(response.text); -} - -analyze_video_with_audio(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/inference/nonStreamMultiModalityBasic.js b/generative-ai/snippets/inference/nonStreamMultiModalityBasic.js deleted file mode 100644 index 32888d06a1..0000000000 --- a/generative-ai/snippets/inference/nonStreamMultiModalityBasic.js +++ /dev/null @@ -1,62 +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 generateContent( - projectId = 'PROJECT_ID', - location = 'us-central1', - model = 'gemini-2.5-flash' -) { - // Initialize client - const client = new GoogleGenAI({ - vertexai: true, - project: projectId, - location: location, - }); - - const result = await client.models.generateContent({ - model: model, - contents: [ - { - role: 'user', - parts: [ - { - fileData: { - fileUri: 'gs://cloud-samples-data/video/animals.mp4', - mimeType: 'video/mp4', - }, - }, - { - fileData: { - fileUri: - 'gs://cloud-samples-data/generative-ai/image/character.jpg', - mimeType: 'image/jpeg', - }, - }, - {text: 'Are this video and image correlated?'}, - ], - }, - ], - }); - - console.log(result.text); -} - -generateContent(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/inference/nonStreamTextBasic.js b/generative-ai/snippets/inference/nonStreamTextBasic.js deleted file mode 100644 index ba2461e19d..0000000000 --- a/generative-ai/snippets/inference/nonStreamTextBasic.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 generateContent( - 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 request = { - model: model, - contents: [ - { - role: 'user', - parts: [ - { - text: 'Write a story about a magic backpack.', - }, - ], - }, - ], - }; - - console.log(JSON.stringify(request)); - - const response = await client.models.generateContent(request); - - console.log(response.text); -} - -generateContent(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/inference/streamMultiModalityBasic.js b/generative-ai/snippets/inference/streamMultiModalityBasic.js deleted file mode 100644 index 9071b6a14a..0000000000 --- a/generative-ai/snippets/inference/streamMultiModalityBasic.js +++ /dev/null @@ -1,68 +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 generateContent( - projectId = 'PROJECT_ID', - location = 'us-central1', - model = 'gemini-2.5-flash' -) { - // Initialize client - const client = new GoogleGenAI({ - vertexai: true, - project: projectId, - location: location, - }); - - const request = { - model: model, - contents: [ - { - role: 'user', - parts: [ - { - fileData: { - fileUri: 'gs://cloud-samples-data/video/animals.mp4', - mimeType: 'video/mp4', - }, - }, - { - fileData: { - fileUri: - 'gs://cloud-samples-data/generative-ai/image/character.jpg', - mimeType: 'image/jpeg', - }, - }, - {text: 'Are this video and image correlated?'}, - ], - }, - ], - }; - - const responseStream = await client.models.generateContentStream(request); - - for await (const chunk of responseStream) { - console.log(chunk.text); - } -} - -generateContent(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/inference/streamTextBasic.js b/generative-ai/snippets/inference/streamTextBasic.js deleted file mode 100644 index ef4f960704..0000000000 --- a/generative-ai/snippets/inference/streamTextBasic.js +++ /dev/null @@ -1,58 +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 generateContent( - 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 request = { - model: model, - contents: [ - { - role: 'user', - parts: [ - { - text: 'Write a story about a magic backpack.', - }, - ], - }, - ], - }; - console.log(JSON.stringify(request)); - - const responseStream = await client.models.generateContentStream(request); - - for await (const chunk of responseStream) { - console.log(chunk.text); - } -} - -generateContent(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/streamMultipartContent.js b/generative-ai/snippets/streamMultipartContent.js deleted file mode 100644 index e4d7f58d6d..0000000000 --- a/generative-ai/snippets/streamMultipartContent.js +++ /dev/null @@ -1,68 +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. - -const {VertexAI} = require('@google-cloud/vertexai'); - -/** - * TODO(developer): Update these variables before running the sample. - */ -async function createStreamMultipartContent( - projectId = 'PROJECT_ID', - location = 'us-central1', - model = 'gemini-2.0-flash-001', - image = 'gs://generativeai-downloads/images/scones.jpg', - mimeType = 'image/jpeg' -) { - // Initialize Vertex with your Cloud project and location - const vertexAI = new VertexAI({project: projectId, location: location}); - - // Instantiate the model - const generativeVisionModel = vertexAI.getGenerativeModel({ - model: model, - }); - - // For images, the SDK supports both Google Cloud Storage URI and base64 strings - const filePart = { - fileData: { - fileUri: image, - mimeType: mimeType, - }, - }; - - const textPart = { - text: 'what is shown in this image?', - }; - - const request = { - contents: [{role: 'user', parts: [filePart, textPart]}], - }; - - console.log('Prompt Text:'); - console.log(request.contents[0].parts[1].text); - console.log('Streaming Response Text:'); - - // Create the response stream - const responseStream = - await generativeVisionModel.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); - } -} - -createStreamMultipartContent(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/test/gemini-video-audio.test.js b/generative-ai/snippets/test/gemini-video-audio.test.js deleted file mode 100644 index dfa6123a30..0000000000 --- a/generative-ai/snippets/test/gemini-video-audio.test.js +++ /dev/null @@ -1,33 +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 model = 'gemini-2.5-flash'; - -describe('Analyze video with audio', async () => { - it('should analyze video with audio', async () => { - const output = execSync( - `node ./gemini-video-audio.js ${projectId} ${model}` - ); - - assert(output.length > 0); - }); -}); diff --git a/generative-ai/snippets/test/inference/nonStreamMultiModalityBasic.test.js b/generative-ai/snippets/test/inference/nonStreamMultiModalityBasic.test.js deleted file mode 100644 index b86671c7d0..0000000000 --- a/generative-ai/snippets/test/inference/nonStreamMultiModalityBasic.test.js +++ /dev/null @@ -1,33 +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 model = 'gemini-2.5-flash'; - -describe('Generative AI Multimodal Text Inference', () => { - it('should generate text based on a prompt containing text, a video, and an image', async () => { - const output = execSync( - `node ./inference/nonStreamMultiModalityBasic.js ${projectId} ${location} ${model}` - ); - assert(output.length > 0); - }); -}); diff --git a/generative-ai/snippets/test/inference/nonStreamTextBasic.test.js b/generative-ai/snippets/test/inference/nonStreamTextBasic.test.js deleted file mode 100644 index e106744c27..0000000000 --- a/generative-ai/snippets/test/inference/nonStreamTextBasic.test.js +++ /dev/null @@ -1,35 +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 model = 'gemini-2.5-flash'; - -describe('Generative AI Basic Text Inference', () => { - it('should create a generative text model and infer text from a prompt', async () => { - const output = execSync( - `node ./inference/nonStreamTextBasic.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/inference/streamMultiModalityBasic.test.js b/generative-ai/snippets/test/inference/streamMultiModalityBasic.test.js deleted file mode 100644 index 3f95952cca..0000000000 --- a/generative-ai/snippets/test/inference/streamMultiModalityBasic.test.js +++ /dev/null @@ -1,33 +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 model = 'gemini-2.5-flash'; - -describe('Generative AI Basic Multimodal Text Inference Streaming', () => { - it('should create a generative text model and infer text from a prompt, streaming the results', async () => { - const output = execSync( - `node ./inference/streamMultiModalityBasic.js ${projectId} ${location} ${model}` - ); - assert(output.length > 0); - }); -}); diff --git a/generative-ai/snippets/test/inference/streamTextBasic.test.js b/generative-ai/snippets/test/inference/streamTextBasic.test.js deleted file mode 100644 index b3f2b1eea7..0000000000 --- a/generative-ai/snippets/test/inference/streamTextBasic.test.js +++ /dev/null @@ -1,33 +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 model = 'gemini-2.5-flash'; - -describe('Generative AI Basic Text Inference Streaming', () => { - it('should create a generative text model and infer text from a prompt, streaming the results', async () => { - const output = execSync( - `node ./inference/streamTextBasic.js ${projectId} ${location} ${model}` - ); - assert(output.length > 0); - }); -}); diff --git a/generative-ai/snippets/test/streamMultipartContent.test.js b/generative-ai/snippets/test/streamMultipartContent.test.js deleted file mode 100644 index ad5e7b6dcc..0000000000 --- a/generative-ai/snippets/test/streamMultipartContent.test.js +++ /dev/null @@ -1,49 +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 Multipart 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'; - - const image = 'gs://generativeai-downloads/images/scones.jpg'; - - it('should create stream multipart content', async () => { - const output = execSync( - `node ./streamMultipartContent.js ${projectId} ${location} ${model} ${image}` - ); - // Split up conversation output - const conversation = output.split('\n'); - - // Ensure that the conversation is what we expect for this scone image - assert(conversation[0].match(/Prompt Text:/)); - assert(conversation[1].match(/what is shown in this image/)); - assert(conversation[2].match(/Streaming Response Text:/)); - }); -});