Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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.
29 changes: 29 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,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-transcript-with-gcs-audio.js');

describe('textgen-transcript-with-gcs-audio', async () => {
it('should generate text content from gsc audio with transcript', async function () {
this.timeout(30000);
const output = await sample.generateContent(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.generateContent(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.generateContent(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.generateContent(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.generateContent(projectId);
assert(output.length > 0);
});
});
66 changes: 66 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,66 @@
// 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 generateContent(
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const ai = 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 ai.models.generateContent({
model: 'gemini-2.5-flash',
contents: [
{text: prompt},
{
fileData: {
fileUri: 'gs://cloud-samples-data/generative-ai/audio/pixel.mp3',
mimeType: 'audio/mpeg',
},
},
],
config: {
audioTimestamp: true,
},
});

console.log(response.text);

return 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. ...
// ...
// [END googlegenaisdk_textgen_transcript_with_gcs_audio]

module.exports = {
generateContent,
};
60 changes: 60 additions & 0 deletions genai/text-generation/textgen-with-gcs-audio.js
Original file line number Diff line number Diff line change
@@ -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_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 generateContent(
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const ai = 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 ai.models.generateContent({
model: 'gemini-2.5-flash',
contents: [
{text: prompt},
{
fileData: {
fileUri: 'gs://cloud-samples-data/generative-ai/audio/pixel.mp3',
mimeType: 'audio/mpeg',
},
},
],
});

console.log(response.text);

return 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.
// [END googlegenaisdk_textgen_with_gcs_audio]

module.exports = {
generateContent,
};
62 changes: 62 additions & 0 deletions genai/text-generation/textgen-with-local-video.js
Original file line number Diff line number Diff line change
@@ -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_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 generateContent(
projectId = GOOGLE_CLOUD_PROJECT,
location = GOOGLE_CLOUD_LOCATION
) {
const ai = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
});

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

const response = await ai.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);

return 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**
// ...
// [END googlegenaisdk_textgen_with_local_video]

module.exports = {
generateContent,
};
Loading