-
Notifications
You must be signed in to change notification settings - Fork 2k
feat(genai): Sample/textgen part2 #4161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gericdong
merged 20 commits into
GoogleCloudPlatform:main
from
Guiners:sample/textgen-part2
Sep 11, 2025
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
dec8528
adding samples, test, lints
db683bd
adding samples, test, lints
734fa06
adding samples, test, lints
7ced756
adding samples, test, lints
05f7a64
adding samples, test, lints
e7839f6
adding samples, test, lints
fb8a749
adding samples, test, lints
eec021b
Merge branch 'main' into sample/textgen-part2
Guiners ac65a59
Merge branch 'main' into sample/textgen-part2
Guiners c779c14
Merge branch 'main' into sample/textgen-part2
Guiners 5664c95
Update genai/text-generation/textgen-transcript-with-gcs-audio.js
Guiners 0f4919a
adding samples, test, lints
8d82322
adding samples, test, lints
e41a282
Merge branch 'main' into sample/textgen-part2
msampathkumar 82fc47d
adding samples, test, lints
0c01cdf
Merge remote-tracking branch 'origin/sample/textgen-part2' into sampl…
3ec7931
adding samples, test, lints
ea5fb69
Merge branch 'main' into sample/textgen-part2
Guiners dea5998
fixing functions names
458e571
Merge branch 'main' into sample/textgen-part2
gericdong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
genai/text-generation/textgen-transcript-with-gcs-audio.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.