From 7f4853392e0a31e5bc713ade32b76760de94ecf9 Mon Sep 17 00:00:00 2001 From: Guiners Date: Thu, 7 Aug 2025 16:28:18 +0200 Subject: [PATCH 01/10] adding samples and tests --- genai/test/textgen-async-with-txt.test.js | 29 +++++++++ genai/test/textgen-chat-with-txt.test.js | 29 +++++++++ genai/test/textgen-config-with-txt.test.js | 29 +++++++++ genai/test/textgen-with-mute-video.test.js | 29 +++++++++ .../text-generation/textgen-async-with-txt.js | 50 +++++++++++++++ .../text-generation/textgen-chat-with-txt.js | 56 +++++++++++++++++ .../textgen-config-with-txt.js | 60 ++++++++++++++++++ .../textgen-with-mute-video.js | 62 +++++++++++++++++++ 8 files changed, 344 insertions(+) create mode 100644 genai/test/textgen-async-with-txt.test.js create mode 100644 genai/test/textgen-chat-with-txt.test.js create mode 100644 genai/test/textgen-config-with-txt.test.js create mode 100644 genai/test/textgen-with-mute-video.test.js create mode 100644 genai/text-generation/textgen-async-with-txt.js create mode 100644 genai/text-generation/textgen-chat-with-txt.js create mode 100644 genai/text-generation/textgen-config-with-txt.js create mode 100644 genai/text-generation/textgen-with-mute-video.js diff --git a/genai/test/textgen-async-with-txt.test.js b/genai/test/textgen-async-with-txt.test.js new file mode 100644 index 0000000000..9ad4f90910 --- /dev/null +++ b/genai/test/textgen-async-with-txt.test.js @@ -0,0 +1,29 @@ +// Copyright 2025 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 projectId = process.env.CAIP_PROJECT_ID; +const sample = require('../text-generation/textgen-async-with-txt.js'); + +describe('textgen-async-with-txt', () => { + it('should generate text content from a text prompt and with system instructions', async function () { + this.timeout(100000); + const output = await sample.generateContent(projectId); + assert(output.length > 0); + }); +}); diff --git a/genai/test/textgen-chat-with-txt.test.js b/genai/test/textgen-chat-with-txt.test.js new file mode 100644 index 0000000000..0bbceb191d --- /dev/null +++ b/genai/test/textgen-chat-with-txt.test.js @@ -0,0 +1,29 @@ +// Copyright 2025 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 projectId = process.env.CAIP_PROJECT_ID; +const sample = require('../text-generation/textgen-chat-with-txt.js'); + +describe('textgen-chat-with-txt', () => { + it('should generate text content from a text prompt and with system instructions', async function () { + this.timeout(100000); + const output = await sample.generateContent(projectId); + assert(output.length > 0); + }); +}); diff --git a/genai/test/textgen-config-with-txt.test.js b/genai/test/textgen-config-with-txt.test.js new file mode 100644 index 0000000000..3c9aaf0690 --- /dev/null +++ b/genai/test/textgen-config-with-txt.test.js @@ -0,0 +1,29 @@ +// Copyright 2025 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 projectId = process.env.CAIP_PROJECT_ID; +const sample = require('../text-generation/textgen-config-with-txt.js'); + +describe('textgen-config-with-txt', () => { + it('should generate text content from a text prompt and with system instructions', async function () { + this.timeout(100000); + const output = await sample.generateContent(projectId); + assert(output.length > 0); + }); +}); diff --git a/genai/test/textgen-with-mute-video.test.js b/genai/test/textgen-with-mute-video.test.js new file mode 100644 index 0000000000..a897c93a67 --- /dev/null +++ b/genai/test/textgen-with-mute-video.test.js @@ -0,0 +1,29 @@ +// Copyright 2025 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 projectId = process.env.CAIP_PROJECT_ID; +const sample = require('../text-generation/textgen-with-mute-video.js'); + +describe('textgen-with-mute-video', () => { + it('should generate text content from a mute video', async function () { + this.timeout(100000); + const output = await sample.generateContent(projectId); + assert(output.length > 0); + }); +}); diff --git a/genai/text-generation/textgen-async-with-txt.js b/genai/text-generation/textgen-async-with-txt.js new file mode 100644 index 0000000000..2b070fd47d --- /dev/null +++ b/genai/text-generation/textgen-async-with-txt.js @@ -0,0 +1,50 @@ +// Copyright 2025 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 googlegenaisdk_textgen_async_with_txt] +const {GoogleGenAI} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +async function generateContent( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + + const response = await ai.models.generateContent({ + model: 'gemini-2.5-flash', + contents: 'Compose a song about the adventures of a time-traveling nuggets.', + config: { + responseMimeType: 'text/plain', + } + }); + + console.log(response.text); + + return response.text; +} +// [END googlegenaisdk_textgen_async_with_txt] + +module.exports = { + generateContent, +}; diff --git a/genai/text-generation/textgen-chat-with-txt.js b/genai/text-generation/textgen-chat-with-txt.js new file mode 100644 index 0000000000..e77666554a --- /dev/null +++ b/genai/text-generation/textgen-chat-with-txt.js @@ -0,0 +1,56 @@ +// Copyright 2025 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 googlegenaisdk_textgen_chat_with_txt] +const {GoogleGenAI} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +async function generateContent( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const chatSession = ai.chats.create({ + model: 'gemini-2.5-flash', + history: [ + { + role: 'user', + parts: [{ text: 'Hello' }], + }, + { + role: 'model', + parts: [{ text: 'Great to meet you. What would you like to know?' }], + }, + ], + }); + + const response = await chatSession.sendMessage({message: 'Tell me a story.'}); + console.log(response.text); + + return response.text; +} +// [END googlegenaisdk_textgen_chat_with_txt] + +module.exports = { + generateContent, +}; diff --git a/genai/text-generation/textgen-config-with-txt.js b/genai/text-generation/textgen-config-with-txt.js new file mode 100644 index 0000000000..ce041017e0 --- /dev/null +++ b/genai/text-generation/textgen-config-with-txt.js @@ -0,0 +1,60 @@ +// Copyright 2025 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 googlegenaisdk_textgen_config_with_txt] +const {GoogleGenAI} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +async function generateContent( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const config = { + temperature: 0, + candidateCount: 1, + responseMimeType: 'application/json', + topP: 0.95, + topK: 20, + seed: 5, + maxOutputTokens: 500, + stopSequences: ['STOP!'], + presencePenalty: 0.0, + frequencyPenalty: 0.0, + }; + + const response = await ai.models.generateContent({ + model: 'gemini-2.5-flash', + contents: 'Why is the sky blue?', + config: config + }); + + console.log(response.text); + + return response.text; +} +// [END googlegenaisdk_textgen_config_with_txt] + +module.exports = { + generateContent, +}; diff --git a/genai/text-generation/textgen-with-mute-video.js b/genai/text-generation/textgen-with-mute-video.js new file mode 100644 index 0000000000..f42b36d31f --- /dev/null +++ b/genai/text-generation/textgen-with-mute-video.js @@ -0,0 +1,62 @@ +// Copyright 2025 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 googlegenaisdk_textgen_with_mute_video] +const {GoogleGenAI} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +async function generateContent( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + + const response = await ai.models.generateContent({ + model: 'gemini-2.5-flash', + contents: [ + { + role: 'user', + parts: [ + { + fileData: { + mimeType: 'video/mp4', + fileUri: 'gs://cloud-samples-data/generative-ai/video/ad_copy_from_video.mp4', + }, + }, + { + text: 'What is in the video?', + }, + ], + }, + ], + }); + + console.log(response.text); + + return response.text; +} +// [END googlegenaisdk_textgen_with_mute_video] + +module.exports = { + generateContent, +}; From 7d7a3f42e2c76b387929bce575a2493ef3a62510 Mon Sep 17 00:00:00 2001 From: Guiners Date: Fri, 8 Aug 2025 11:40:07 +0200 Subject: [PATCH 02/10] adding samples, test, lints --- .../test/textgen-chat-stream-with-txt.test.js | 29 +++++++++++ .../text-generation/textgen-async-with-txt.js | 6 +-- .../textgen-chat-stream-with-txt.js | 49 +++++++++++++++++++ .../text-generation/textgen-chat-with-txt.js | 4 +- .../textgen-config-with-txt.js | 2 +- .../textgen-with-mute-video.js | 4 +- 6 files changed, 86 insertions(+), 8 deletions(-) create mode 100644 genai/test/textgen-chat-stream-with-txt.test.js create mode 100644 genai/text-generation/textgen-chat-stream-with-txt.js diff --git a/genai/test/textgen-chat-stream-with-txt.test.js b/genai/test/textgen-chat-stream-with-txt.test.js new file mode 100644 index 0000000000..bc0a4be437 --- /dev/null +++ b/genai/test/textgen-chat-stream-with-txt.test.js @@ -0,0 +1,29 @@ +// Copyright 2025 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 projectId = process.env.CAIP_PROJECT_ID; +const sample = require('../text-generation/textgen-chat-stream-with-txt.js'); + +describe('textgen-chat-stream-with-txt', () => { + it('should generate text content from a mute video', async function () { + this.timeout(100000); + const output = await sample.generateContent(projectId); + assert.isTrue(output); + }); +}); diff --git a/genai/text-generation/textgen-async-with-txt.js b/genai/text-generation/textgen-async-with-txt.js index 2b070fd47d..1be6e49467 100644 --- a/genai/text-generation/textgen-async-with-txt.js +++ b/genai/text-generation/textgen-async-with-txt.js @@ -30,13 +30,13 @@ async function generateContent( location: location, }); - const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', - contents: 'Compose a song about the adventures of a time-traveling nuggets.', + contents: + 'Compose a song about the adventures of a time-traveling nuggets.', config: { responseMimeType: 'text/plain', - } + }, }); console.log(response.text); diff --git a/genai/text-generation/textgen-chat-stream-with-txt.js b/genai/text-generation/textgen-chat-stream-with-txt.js new file mode 100644 index 0000000000..3e862bc969 --- /dev/null +++ b/genai/text-generation/textgen-chat-stream-with-txt.js @@ -0,0 +1,49 @@ +// Copyright 2025 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 googlegenaisdk_textgen_chat_stream_with_txt] +const {GoogleGenAI} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; + +async function generateContent( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const ai = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const chatSession = ai.chats.create({ + model: 'gemini-2.5-flash', + }); + + for await (const chunk of await chatSession.sendMessageStream({ + message: 'Why lava is red?', + })) { + console.log(chunk.text); + } + + return true; +} +// [END googlegenaisdk_textgen_chat_stream_with_txt] + +module.exports = { + generateContent, +}; diff --git a/genai/text-generation/textgen-chat-with-txt.js b/genai/text-generation/textgen-chat-with-txt.js index e77666554a..2db48f4b2e 100644 --- a/genai/text-generation/textgen-chat-with-txt.js +++ b/genai/text-generation/textgen-chat-with-txt.js @@ -35,11 +35,11 @@ async function generateContent( history: [ { role: 'user', - parts: [{ text: 'Hello' }], + parts: [{text: 'Hello'}], }, { role: 'model', - parts: [{ text: 'Great to meet you. What would you like to know?' }], + parts: [{text: 'Great to meet you. What would you like to know?'}], }, ], }); diff --git a/genai/text-generation/textgen-config-with-txt.js b/genai/text-generation/textgen-config-with-txt.js index ce041017e0..43dc2a5ab6 100644 --- a/genai/text-generation/textgen-config-with-txt.js +++ b/genai/text-generation/textgen-config-with-txt.js @@ -46,7 +46,7 @@ async function generateContent( const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: 'Why is the sky blue?', - config: config + config: config, }); console.log(response.text); diff --git a/genai/text-generation/textgen-with-mute-video.js b/genai/text-generation/textgen-with-mute-video.js index f42b36d31f..e997643cf8 100644 --- a/genai/text-generation/textgen-with-mute-video.js +++ b/genai/text-generation/textgen-with-mute-video.js @@ -30,7 +30,6 @@ async function generateContent( location: location, }); - const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: [ @@ -40,7 +39,8 @@ async function generateContent( { fileData: { mimeType: 'video/mp4', - fileUri: 'gs://cloud-samples-data/generative-ai/video/ad_copy_from_video.mp4', + fileUri: + 'gs://cloud-samples-data/generative-ai/video/ad_copy_from_video.mp4', }, }, { From 9b7ee3c4921d9e5fcda9a7a3cd36b4534d1fe02f Mon Sep 17 00:00:00 2001 From: Guiners Date: Mon, 11 Aug 2025 17:14:41 +0200 Subject: [PATCH 03/10] adding samples, test, lints --- genai/test/textgen-chat-with-txt.test.js | 2 +- genai/test/textgen-config-with-txt.test.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/genai/test/textgen-chat-with-txt.test.js b/genai/test/textgen-chat-with-txt.test.js index 0bbceb191d..73c0b005ae 100644 --- a/genai/test/textgen-chat-with-txt.test.js +++ b/genai/test/textgen-chat-with-txt.test.js @@ -21,7 +21,7 @@ const projectId = process.env.CAIP_PROJECT_ID; const sample = require('../text-generation/textgen-chat-with-txt.js'); describe('textgen-chat-with-txt', () => { - it('should generate text content from a text prompt and with system instructions', async function () { + it('should generate chat content from a text prompt', async function () { this.timeout(100000); const output = await sample.generateContent(projectId); assert(output.length > 0); diff --git a/genai/test/textgen-config-with-txt.test.js b/genai/test/textgen-config-with-txt.test.js index 3c9aaf0690..b070952515 100644 --- a/genai/test/textgen-config-with-txt.test.js +++ b/genai/test/textgen-config-with-txt.test.js @@ -21,7 +21,7 @@ const projectId = process.env.CAIP_PROJECT_ID; const sample = require('../text-generation/textgen-config-with-txt.js'); describe('textgen-config-with-txt', () => { - it('should generate text content from a text prompt and with system instructions', async function () { + it('should generate text content from a text prompt with config', async function () { this.timeout(100000); const output = await sample.generateContent(projectId); assert(output.length > 0); From 46a71cd8c77b6cb2c7affcdd09ca685166c5730b Mon Sep 17 00:00:00 2001 From: Guiners Date: Wed, 20 Aug 2025 12:20:02 +0200 Subject: [PATCH 04/10] adding samples, test, lints --- genai/text-generation/textgen-async-with-txt.js | 4 ++++ genai/text-generation/textgen-chat-stream-with-txt.js | 5 +++++ genai/text-generation/textgen-chat-with-txt.js | 3 +++ genai/text-generation/textgen-config-with-txt.js | 4 ++++ genai/text-generation/textgen-with-mute-video.js | 2 ++ 5 files changed, 18 insertions(+) diff --git a/genai/text-generation/textgen-async-with-txt.js b/genai/text-generation/textgen-async-with-txt.js index 1be6e49467..6804ab7e3b 100644 --- a/genai/text-generation/textgen-async-with-txt.js +++ b/genai/text-generation/textgen-async-with-txt.js @@ -43,6 +43,10 @@ async function generateContent( return response.text; } +// Example response: +// (Verse 1) +// Sammy the nugget, a furry little friend +// Had a knack for adventure, beyond all comprehend // [END googlegenaisdk_textgen_async_with_txt] module.exports = { diff --git a/genai/text-generation/textgen-chat-stream-with-txt.js b/genai/text-generation/textgen-chat-stream-with-txt.js index 3e862bc969..b58d20d93b 100644 --- a/genai/text-generation/textgen-chat-stream-with-txt.js +++ b/genai/text-generation/textgen-chat-stream-with-txt.js @@ -42,6 +42,11 @@ async function generateContent( return true; } +// Example response: +// The +// sky appears blue due to a phenomenon called **Rayleigh scattering**. Here's +// a breakdown of why: +// ... // [END googlegenaisdk_textgen_chat_stream_with_txt] module.exports = { diff --git a/genai/text-generation/textgen-chat-with-txt.js b/genai/text-generation/textgen-chat-with-txt.js index 2db48f4b2e..32a8291c65 100644 --- a/genai/text-generation/textgen-chat-with-txt.js +++ b/genai/text-generation/textgen-chat-with-txt.js @@ -49,6 +49,9 @@ async function generateContent( return response.text; } +// Example response: +// Okay, here's a story for you: +// ... // [END googlegenaisdk_textgen_chat_with_txt] module.exports = { diff --git a/genai/text-generation/textgen-config-with-txt.js b/genai/text-generation/textgen-config-with-txt.js index 43dc2a5ab6..53e440b5cb 100644 --- a/genai/text-generation/textgen-config-with-txt.js +++ b/genai/text-generation/textgen-config-with-txt.js @@ -53,6 +53,10 @@ async function generateContent( return response.text; } +// Example response: +// { +// "explanation": "The sky appears blue due to a phenomenon called Rayleigh scattering. When ... +// } // [END googlegenaisdk_textgen_config_with_txt] module.exports = { diff --git a/genai/text-generation/textgen-with-mute-video.js b/genai/text-generation/textgen-with-mute-video.js index e997643cf8..ae25a14e27 100644 --- a/genai/text-generation/textgen-with-mute-video.js +++ b/genai/text-generation/textgen-with-mute-video.js @@ -55,6 +55,8 @@ async function generateContent( return response.text; } +// Example response: +// The video shows several people surfing in an ocean with a coastline in the background. The camera ... // [END googlegenaisdk_textgen_with_mute_video] module.exports = { From a8d084b8c7983fe0d4647dfacd2f200edf8013f3 Mon Sep 17 00:00:00 2001 From: Guiners Date: Wed, 20 Aug 2025 15:39:48 +0200 Subject: [PATCH 05/10] adding samples, test, lints --- genai/test/imggen-mmflash-with-txt.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genai/test/imggen-mmflash-with-txt.test.js b/genai/test/imggen-mmflash-with-txt.test.js index 908adabe3b..44f109b269 100644 --- a/genai/test/imggen-mmflash-with-txt.test.js +++ b/genai/test/imggen-mmflash-with-txt.test.js @@ -24,7 +24,7 @@ const {delay} = require('./util'); describe('imggen-mmflash-with-txt', async () => { it('should generate images from a text prompt', async function () { this.timeout(180000); - this.retries(4); + this.retries(10); await delay(this.test); const generatedFileNames = await sample.generateContent(projectId); assert(Array.isArray(generatedFileNames)); From d5804704817375adf039dca68f5bd27cacbfa244 Mon Sep 17 00:00:00 2001 From: Robert Kozak <50328216+Guiners@users.noreply.github.com> Date: Tue, 2 Sep 2025 12:37:04 +0200 Subject: [PATCH 06/10] Update genai/text-generation/textgen-async-with-txt.js Co-authored-by: Sampath Kumar --- genai/text-generation/textgen-async-with-txt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genai/text-generation/textgen-async-with-txt.js b/genai/text-generation/textgen-async-with-txt.js index 6804ab7e3b..6e3506d4ae 100644 --- a/genai/text-generation/textgen-async-with-txt.js +++ b/genai/text-generation/textgen-async-with-txt.js @@ -33,7 +33,7 @@ async function generateContent( const response = await ai.models.generateContent({ model: 'gemini-2.5-flash', contents: - 'Compose a song about the adventures of a time-traveling nuggets.', + 'Compose a song about the adventures of a time-traveling squirrel.', config: { responseMimeType: 'text/plain', }, From 2e9fb526ce1e80178cc30479a58212ec0d632e40 Mon Sep 17 00:00:00 2001 From: Robert Kozak <50328216+Guiners@users.noreply.github.com> Date: Tue, 2 Sep 2025 12:37:10 +0200 Subject: [PATCH 07/10] Update genai/text-generation/textgen-chat-stream-with-txt.js Co-authored-by: Sampath Kumar --- genai/text-generation/textgen-chat-stream-with-txt.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genai/text-generation/textgen-chat-stream-with-txt.js b/genai/text-generation/textgen-chat-stream-with-txt.js index b58d20d93b..6c527ad912 100644 --- a/genai/text-generation/textgen-chat-stream-with-txt.js +++ b/genai/text-generation/textgen-chat-stream-with-txt.js @@ -35,7 +35,7 @@ async function generateContent( }); for await (const chunk of await chatSession.sendMessageStream({ - message: 'Why lava is red?', + message: 'Why is the sky blue?', })) { console.log(chunk.text); } From 16cf0864adf7bb9ad76c8d0765eda7d38e632e10 Mon Sep 17 00:00:00 2001 From: Guiners Date: Thu, 4 Sep 2025 11:00:33 +0200 Subject: [PATCH 08/10] adding samples, test, lints --- genai/text-generation/textgen-async-with-txt.js | 10 ++++++---- .../text-generation/textgen-chat-stream-with-txt.js | 12 ++++++------ genai/text-generation/textgen-chat-with-txt.js | 8 +++++--- genai/text-generation/textgen-config-with-txt.js | 10 ++++++---- genai/text-generation/textgen-with-mute-video.js | 5 +++-- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/genai/text-generation/textgen-async-with-txt.js b/genai/text-generation/textgen-async-with-txt.js index 6e3506d4ae..d2b56a921b 100644 --- a/genai/text-generation/textgen-async-with-txt.js +++ b/genai/text-generation/textgen-async-with-txt.js @@ -41,12 +41,14 @@ async function generateContent( console.log(response.text); + // Example response: + // (Verse 1) + // Sammy the nugget, a furry little friend + // Had a knack for adventure, beyond all comprehend + return response.text; } -// Example response: -// (Verse 1) -// Sammy the nugget, a furry little friend -// Had a knack for adventure, beyond all comprehend + // [END googlegenaisdk_textgen_async_with_txt] module.exports = { diff --git a/genai/text-generation/textgen-chat-stream-with-txt.js b/genai/text-generation/textgen-chat-stream-with-txt.js index 6c527ad912..b05eb43754 100644 --- a/genai/text-generation/textgen-chat-stream-with-txt.js +++ b/genai/text-generation/textgen-chat-stream-with-txt.js @@ -39,14 +39,14 @@ async function generateContent( })) { console.log(chunk.text); } - + // Example response: + // The + // sky appears blue due to a phenomenon called **Rayleigh scattering**. Here's + // a breakdown of why: + // ... return true; } -// Example response: -// The -// sky appears blue due to a phenomenon called **Rayleigh scattering**. Here's -// a breakdown of why: -// ... + // [END googlegenaisdk_textgen_chat_stream_with_txt] module.exports = { diff --git a/genai/text-generation/textgen-chat-with-txt.js b/genai/text-generation/textgen-chat-with-txt.js index 32a8291c65..7f7ae09b14 100644 --- a/genai/text-generation/textgen-chat-with-txt.js +++ b/genai/text-generation/textgen-chat-with-txt.js @@ -47,11 +47,13 @@ async function generateContent( const response = await chatSession.sendMessage({message: 'Tell me a story.'}); console.log(response.text); + // Example response: + // Okay, here's a story for you: + // ... + return response.text; } -// Example response: -// Okay, here's a story for you: -// ... + // [END googlegenaisdk_textgen_chat_with_txt] module.exports = { diff --git a/genai/text-generation/textgen-config-with-txt.js b/genai/text-generation/textgen-config-with-txt.js index 53e440b5cb..f9c45a27a4 100644 --- a/genai/text-generation/textgen-config-with-txt.js +++ b/genai/text-generation/textgen-config-with-txt.js @@ -51,12 +51,14 @@ async function generateContent( console.log(response.text); + // Example response: + // { + // "explanation": "The sky appears blue due to a phenomenon called Rayleigh scattering. When ... + // } + return response.text; } -// Example response: -// { -// "explanation": "The sky appears blue due to a phenomenon called Rayleigh scattering. When ... -// } + // [END googlegenaisdk_textgen_config_with_txt] module.exports = { diff --git a/genai/text-generation/textgen-with-mute-video.js b/genai/text-generation/textgen-with-mute-video.js index ae25a14e27..7021d117c9 100644 --- a/genai/text-generation/textgen-with-mute-video.js +++ b/genai/text-generation/textgen-with-mute-video.js @@ -53,10 +53,11 @@ async function generateContent( console.log(response.text); + // Example response: + // The video shows several people surfing in an ocean with a coastline in the background. The camera ... + return response.text; } -// Example response: -// The video shows several people surfing in an ocean with a coastline in the background. The camera ... // [END googlegenaisdk_textgen_with_mute_video] module.exports = { From edd09030e0623838db1732186da2514e5fde6d39 Mon Sep 17 00:00:00 2001 From: Guiners Date: Fri, 5 Sep 2025 10:21:46 +0200 Subject: [PATCH 09/10] adding samples, test, lints --- genai/text-generation/textgen-async-with-txt.js | 4 ++-- genai/text-generation/textgen-chat-stream-with-txt.js | 4 ++-- genai/text-generation/textgen-chat-with-txt.js | 4 ++-- genai/text-generation/textgen-config-with-txt.js | 4 ++-- genai/text-generation/textgen-with-mute-video.js | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/genai/text-generation/textgen-async-with-txt.js b/genai/text-generation/textgen-async-with-txt.js index d2b56a921b..67084afb54 100644 --- a/genai/text-generation/textgen-async-with-txt.js +++ b/genai/text-generation/textgen-async-with-txt.js @@ -24,13 +24,13 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, }); - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-flash', contents: 'Compose a song about the adventures of a time-traveling squirrel.', diff --git a/genai/text-generation/textgen-chat-stream-with-txt.js b/genai/text-generation/textgen-chat-stream-with-txt.js index b05eb43754..5926643fbc 100644 --- a/genai/text-generation/textgen-chat-stream-with-txt.js +++ b/genai/text-generation/textgen-chat-stream-with-txt.js @@ -24,13 +24,13 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, }); - const chatSession = ai.chats.create({ + const chatSession = client.chats.create({ model: 'gemini-2.5-flash', }); diff --git a/genai/text-generation/textgen-chat-with-txt.js b/genai/text-generation/textgen-chat-with-txt.js index 7f7ae09b14..cdc665c7a4 100644 --- a/genai/text-generation/textgen-chat-with-txt.js +++ b/genai/text-generation/textgen-chat-with-txt.js @@ -24,13 +24,13 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, }); - const chatSession = ai.chats.create({ + const chatSession = client.chats.create({ model: 'gemini-2.5-flash', history: [ { diff --git a/genai/text-generation/textgen-config-with-txt.js b/genai/text-generation/textgen-config-with-txt.js index f9c45a27a4..46d4e7b1c4 100644 --- a/genai/text-generation/textgen-config-with-txt.js +++ b/genai/text-generation/textgen-config-with-txt.js @@ -24,7 +24,7 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, @@ -43,7 +43,7 @@ async function generateContent( frequencyPenalty: 0.0, }; - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-flash', contents: 'Why is the sky blue?', config: config, diff --git a/genai/text-generation/textgen-with-mute-video.js b/genai/text-generation/textgen-with-mute-video.js index 7021d117c9..9824a09761 100644 --- a/genai/text-generation/textgen-with-mute-video.js +++ b/genai/text-generation/textgen-with-mute-video.js @@ -24,13 +24,13 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, }); - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-flash', contents: [ { From 6729ca7b10a5db597176281d826e145dbd28e684 Mon Sep 17 00:00:00 2001 From: Guiners Date: Wed, 10 Sep 2025 11:01:50 +0200 Subject: [PATCH 10/10] fixing functions names --- genai/test/textgen-async-with-txt.test.js | 2 +- genai/test/textgen-chat-stream-with-txt.test.js | 2 +- genai/test/textgen-chat-with-txt.test.js | 2 +- genai/test/textgen-code-with-pdf.test.js | 2 +- genai/test/textgen-with-mute-video.test.js | 2 +- genai/text-generation/textgen-async-with-txt.js | 4 ++-- genai/text-generation/textgen-chat-stream-with-txt.js | 4 ++-- genai/text-generation/textgen-chat-with-txt.js | 4 ++-- genai/text-generation/textgen-code-with-pdf.js | 4 ++-- genai/text-generation/textgen-with-mute-video.js | 4 ++-- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/genai/test/textgen-async-with-txt.test.js b/genai/test/textgen-async-with-txt.test.js index 9ad4f90910..540ff3e682 100644 --- a/genai/test/textgen-async-with-txt.test.js +++ b/genai/test/textgen-async-with-txt.test.js @@ -23,7 +23,7 @@ const sample = require('../text-generation/textgen-async-with-txt.js'); describe('textgen-async-with-txt', () => { it('should generate text content from a text prompt and with system instructions', async function () { this.timeout(100000); - const output = await sample.generateContent(projectId); + const output = await sample.generateText(projectId); assert(output.length > 0); }); }); diff --git a/genai/test/textgen-chat-stream-with-txt.test.js b/genai/test/textgen-chat-stream-with-txt.test.js index bc0a4be437..a81fdb4031 100644 --- a/genai/test/textgen-chat-stream-with-txt.test.js +++ b/genai/test/textgen-chat-stream-with-txt.test.js @@ -23,7 +23,7 @@ const sample = require('../text-generation/textgen-chat-stream-with-txt.js'); describe('textgen-chat-stream-with-txt', () => { it('should generate text content from a mute video', async function () { this.timeout(100000); - const output = await sample.generateContent(projectId); + const output = await sample.generateText(projectId); assert.isTrue(output); }); }); diff --git a/genai/test/textgen-chat-with-txt.test.js b/genai/test/textgen-chat-with-txt.test.js index 73c0b005ae..184013536c 100644 --- a/genai/test/textgen-chat-with-txt.test.js +++ b/genai/test/textgen-chat-with-txt.test.js @@ -23,7 +23,7 @@ const sample = require('../text-generation/textgen-chat-with-txt.js'); describe('textgen-chat-with-txt', () => { it('should generate chat content from a text prompt', async function () { this.timeout(100000); - const output = await sample.generateContent(projectId); + const output = await sample.generateText(projectId); assert(output.length > 0); }); }); diff --git a/genai/test/textgen-code-with-pdf.test.js b/genai/test/textgen-code-with-pdf.test.js index d4a11130a1..22ec5b77fe 100644 --- a/genai/test/textgen-code-with-pdf.test.js +++ b/genai/test/textgen-code-with-pdf.test.js @@ -23,7 +23,7 @@ const sample = require('../text-generation/textgen-code-with-pdf.js'); describe('textgen-code-with-pdf', () => { it('should generate text content from a pdf', async function () { this.timeout(100000); - const output = await sample.generateContent(projectId); + const output = await sample.generateText(projectId); assert(output.length > 0); }); }); diff --git a/genai/test/textgen-with-mute-video.test.js b/genai/test/textgen-with-mute-video.test.js index a897c93a67..65b5013126 100644 --- a/genai/test/textgen-with-mute-video.test.js +++ b/genai/test/textgen-with-mute-video.test.js @@ -23,7 +23,7 @@ const sample = require('../text-generation/textgen-with-mute-video.js'); describe('textgen-with-mute-video', () => { it('should generate text content from a mute video', async function () { this.timeout(100000); - const output = await sample.generateContent(projectId); + const output = await sample.generateText(projectId); assert(output.length > 0); }); }); diff --git a/genai/text-generation/textgen-async-with-txt.js b/genai/text-generation/textgen-async-with-txt.js index 67084afb54..c47f59b4fa 100644 --- a/genai/text-generation/textgen-async-with-txt.js +++ b/genai/text-generation/textgen-async-with-txt.js @@ -20,7 +20,7 @@ const {GoogleGenAI} = require('@google/genai'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -async function generateContent( +async function generateText( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { @@ -52,5 +52,5 @@ async function generateContent( // [END googlegenaisdk_textgen_async_with_txt] module.exports = { - generateContent, + generateText, }; diff --git a/genai/text-generation/textgen-chat-stream-with-txt.js b/genai/text-generation/textgen-chat-stream-with-txt.js index 5926643fbc..9276368582 100644 --- a/genai/text-generation/textgen-chat-stream-with-txt.js +++ b/genai/text-generation/textgen-chat-stream-with-txt.js @@ -20,7 +20,7 @@ const {GoogleGenAI} = require('@google/genai'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -async function generateContent( +async function generateText( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { @@ -50,5 +50,5 @@ async function generateContent( // [END googlegenaisdk_textgen_chat_stream_with_txt] module.exports = { - generateContent, + generateText, }; diff --git a/genai/text-generation/textgen-chat-with-txt.js b/genai/text-generation/textgen-chat-with-txt.js index cdc665c7a4..ae81aa9aa5 100644 --- a/genai/text-generation/textgen-chat-with-txt.js +++ b/genai/text-generation/textgen-chat-with-txt.js @@ -20,7 +20,7 @@ const {GoogleGenAI} = require('@google/genai'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -async function generateContent( +async function generateText( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { @@ -57,5 +57,5 @@ async function generateContent( // [END googlegenaisdk_textgen_chat_with_txt] module.exports = { - generateContent, + generateText, }; diff --git a/genai/text-generation/textgen-code-with-pdf.js b/genai/text-generation/textgen-code-with-pdf.js index 762f4bff19..7211d177bc 100644 --- a/genai/text-generation/textgen-code-with-pdf.js +++ b/genai/text-generation/textgen-code-with-pdf.js @@ -20,7 +20,7 @@ const {GoogleGenAI} = require('@google/genai'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -async function generateContent( +async function generateText( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { @@ -74,5 +74,5 @@ async function generateContent( // [END googlegenaisdk_textgen_code_with_pdf] module.exports = { - generateContent, + generateText, }; diff --git a/genai/text-generation/textgen-with-mute-video.js b/genai/text-generation/textgen-with-mute-video.js index 9824a09761..f2a7805064 100644 --- a/genai/text-generation/textgen-with-mute-video.js +++ b/genai/text-generation/textgen-with-mute-video.js @@ -20,7 +20,7 @@ const {GoogleGenAI} = require('@google/genai'); const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global'; -async function generateContent( +async function generateText( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { @@ -61,5 +61,5 @@ async function generateContent( // [END googlegenaisdk_textgen_with_mute_video] module.exports = { - generateContent, + generateText, };