Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added genai/test-data/describe_video_content.mp4
Binary file not shown.
32 changes: 32 additions & 0 deletions genai/test/textgen-transcript-with-gcs-audio.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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-transcript-with-gcs-audio.js');
const {delay} = require('./util');

describe('textgen-transcript-with-gcs-audio', async () => {
it('should generate text content from gsc audio with transcript', async function () {
this.timeout(180000);
this.retries(4);
await delay(this.test);
const output = await sample.generateText(projectId);
assert(output.length > 0);
});
});
29 changes: 29 additions & 0 deletions genai/test/textgen-with-gcs-audio.test.js
Original file line number Diff line number Diff line change
@@ -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-gcs-audio');

describe('textgen-with-gcs-audio', async () => {
it('should generate text content from gsc audio', async function () {
this.timeout(300000);
const output = await sample.generateText(projectId);
assert(output.length > 0);
});
});
29 changes: 29 additions & 0 deletions genai/test/textgen-with-local-video.test.js
Original file line number Diff line number Diff line change
@@ -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-local-video.js');

describe('textgen-with-local-video', async () => {
it('should generate text content from local video', async function () {
this.timeout(30000);
const output = await sample.generateText(projectId);
assert(output.length > 0);
});
});
29 changes: 29 additions & 0 deletions genai/test/textgen-with-pdf.test.js
Original file line number Diff line number Diff line change
@@ -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-pdf.js');

describe('textgen-with-pdf', async () => {
it('should generate text content from pdf', async function () {
this.timeout(30000);
const output = await sample.generateText(projectId);
assert(output.length > 0);
});
});
29 changes: 29 additions & 0 deletions genai/test/textgen-with-youtube-video.test.js
Original file line number Diff line number Diff line change
@@ -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-youtube-video');

describe('textgen-with-youtube-video', async () => {
it('should generate text content from yt video', async function () {
this.timeout(300000);
const output = await sample.generateText(projectId);
assert(output.length > 0);
});
});
34 changes: 18 additions & 16 deletions genai/text-generation/textgen-code-with-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,26 @@ async function generateText(

console.log(response.text);

// Example response:
// Here's the Python code converted to adhere to the Google Python Style Guide, along with explanations for the changes:
//
// ```python
// """Calculates the Fibonacci sequence up to n numbers.
//
// This module provides a function to generate a Fibonacci sequence,
// demonstrating adherence to the Google Python Style Guide.
// """
//
// def fibonacci(n: int) -> list[int]:
// """Calculates the Fibonacci sequence up to n numbers.
//
// This function generates the first 'n' terms of the Fibonacci sequence,
// starting with 0, 1, 1, 2...
// ...

return response.text;
}
// Example response:
// Here's the Python code converted to adhere to the Google Python Style Guide, along with explanations for the changes:
//
// ```python
// """Calculates the Fibonacci sequence up to n numbers.
//
// This module provides a function to generate a Fibonacci sequence,
// demonstrating adherence to the Google Python Style Guide.
// """
//
// def fibonacci(n: int) -> list[int]:
// """Calculates the Fibonacci sequence up to n numbers.
//
// This function generates the first 'n' terms of the Fibonacci sequence,
// starting with 0, 1, 1, 2...
// ...

// [END googlegenaisdk_textgen_code_with_pdf]

module.exports = {
Expand Down
69 changes: 69 additions & 0 deletions genai/text-generation/textgen-transcript-with-gcs-audio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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_transcript_with_gcs_audio]
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 generateText(
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
});

const prompt = `Transcribe the interview, in the format of timecode, speaker, caption.
Use speaker A, speaker B, etc. to identify speakers.`;

const response = await client.models.generateContent({
model: 'gemini-2.5-flash',
contents: [
{text: prompt},
{
fileData: {
fileUri: 'gs://cloud-samples-data/generative-ai/audio/pixel.mp3',
mimeType: 'audio/mpeg',
},
},
],
// Required to enable timestamp understanding for audio-only files
config: {
audioTimestamp: true,
},
});

console.log(response.text);

// Example response:
// [00:00:00] **Speaker A:** your devices are getting better over time. And so ...
// [00:00:14] **Speaker B:** Welcome to the Made by Google podcast where we meet ...
// [00:00:20] **Speaker B:** Here's your host, Rasheed Finch.
// [00:00:23] **Speaker C:** Today we're talking to Aisha Sharif and DeCarlos Love. ...
// ...

return response.text;
}

// [END googlegenaisdk_textgen_transcript_with_gcs_audio]

module.exports = {
generateText,
};
61 changes: 61 additions & 0 deletions genai/text-generation/textgen-with-gcs-audio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// 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_gcs_audio]
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 generateText(
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
});

const prompt =
'Provide a concise summary of the main points in the audio file.';

const response = await client.models.generateContent({
model: 'gemini-2.5-flash',
contents: [
{
fileData: {
fileUri: 'gs://cloud-samples-data/generative-ai/audio/pixel.mp3',
mimeType: 'audio/mpeg',
},
},
{text: prompt},
],
});

console.log(response.text);

// Example response:
// Here's a summary of the main points from the audio file:
// The Made by Google podcast discusses the Pixel feature drops with product managers Aisha Sheriff and De Carlos Love. The key idea is that devices should improve over time, with a connected experience across phones, watches, earbuds, and tablets.

return response.text;
}
// [END googlegenaisdk_textgen_with_gcs_audio]

module.exports = {
generateText,
};
64 changes: 64 additions & 0 deletions genai/text-generation/textgen-with-local-video.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// 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_local_video]
const {GoogleGenAI} = require('@google/genai');
const fs = require('fs');

const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT;
const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'global';

async function generateText(
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
});

const videoContent = fs.readFileSync('test-data/describe_video_content.mp4');

const response = await client.models.generateContent({
model: 'gemini-2.5-flash',
contents: [
{text: 'hello-world'},
{
inlineData: {
data: videoContent.toString('base64'),
mimeType: 'video/mp4',
},
},
{text: 'Write a short and engaging blog post based on this video.'},
],
});

console.log(response.text);

// Example response:
// Okay, here's a short and engaging blog post based on the climbing video:
// **Title: Conquering the Wall: A Glimpse into the World of Indoor Climbing**
// ...

return response.text;
}

// [END googlegenaisdk_textgen_with_local_video]

module.exports = {
generateText,
};
Loading
Loading