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
38 changes: 20 additions & 18 deletions generative-ai/snippets/gemini-all-modalities.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,33 @@
// limitations under the License.

// [START generativeaionvertexai_gemini_all_modalities]
const {VertexAI} = require('@google-cloud/vertexai');
const {GoogleGenAI} = require('@google/genai');

/**
* TODO(developer): Update these variables before running the sample.
*/
async function analyze_all_modalities(projectId = 'PROJECT_ID') {
const vertexAI = new VertexAI({project: projectId, location: 'us-central1'});

const generativeModel = vertexAI.getGenerativeModel({
model: 'gemini-2.0-flash-001',
async function analyze_all_modalities(
projectId = 'PROJECT_ID',
model = 'gemini-2.5-flash'
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: 'us-central1',
});

const videoFilePart = {
file_data: {
file_uri:
fileData: {
fileUri:
'gs://cloud-samples-data/generative-ai/video/behind_the_scenes_pixel.mp4',
mime_type: 'video/mp4',
mimeType: 'video/mp4',
},
};
const imageFilePart = {
file_data: {
file_uri:
fileData: {
fileUri:
'gs://cloud-samples-data/generative-ai/image/a-man-and-a-dog.png',
mime_type: 'image/png',
mimeType: 'image/png',
},
};

Expand All @@ -52,13 +55,12 @@ async function analyze_all_modalities(projectId = 'PROJECT_ID') {
- What is the context of the moment and what does the narrator say about it?`,
};

const request = {
contents: [{role: 'user', parts: [videoFilePart, imageFilePart, textPart]}],
};
const response = await client.models.generateContent({
model: model,
contents: [videoFilePart, imageFilePart, textPart],
});

const resp = await generativeModel.generateContent(request);
const contentResponse = await resp.response;
console.log(JSON.stringify(contentResponse));
console.log(response.text);
}
// [END generativeaionvertexai_gemini_all_modalities]

Expand Down
33 changes: 17 additions & 16 deletions generative-ai/snippets/gemini-audio-summarization.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,24 @@
// limitations under the License.

// [START generativeaionvertexai_gemini_audio_summarization]
const {VertexAI} = require('@google-cloud/vertexai');

const {GoogleGenAI} = require('@google/genai');
/**
* TODO(developer): Update these variables before running the sample.
*/
async function summarize_audio(projectId = 'PROJECT_ID') {
const vertexAI = new VertexAI({project: projectId, location: 'us-central1'});

const generativeModel = vertexAI.getGenerativeModel({
model: 'gemini-2.0-flash-001',
async function summarize_audio(
projectId = 'PROJECT_ID',
model = 'gemini-2.5-flash'
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: 'us-central1',
});

const filePart = {
file_data: {
file_uri: 'gs://cloud-samples-data/generative-ai/audio/pixel.mp3',
mime_type: 'audio/mpeg',
fileData: {
fileUri: 'gs://cloud-samples-data/generative-ai/audio/pixel.mp3',
mimeType: 'audio/mpeg',
},
};
const textPart = {
Expand All @@ -38,13 +40,12 @@ async function summarize_audio(projectId = 'PROJECT_ID') {
Do not make up any information that is not part of the audio and do not be verbose.`,
};

const request = {
contents: [{role: 'user', parts: [filePart, textPart]}],
};
const response = await client.models.generateContent({
model: model,
contents: [filePart, textPart],
});

const resp = await generativeModel.generateContent(request);
const contentResponse = await resp.response;
console.log(JSON.stringify(contentResponse));
console.log(response.text);
}
// [END generativeaionvertexai_gemini_audio_summarization]

Expand Down
32 changes: 17 additions & 15 deletions generative-ai/snippets/gemini-audio-transcription.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@
// limitations under the License.

// [START generativeaionvertexai_gemini_audio_transcription]
const {VertexAI} = require('@google-cloud/vertexai');
const {GoogleGenAI} = require('@google/genai');

/**
* TODO(developer): Update these variables before running the sample.
*/
async function transcript_audio(projectId = 'PROJECT_ID') {
const vertexAI = new VertexAI({project: projectId, location: 'us-central1'});

const generativeModel = vertexAI.getGenerativeModel({
model: 'gemini-2.0-flash-001',
async function transcript_audio(
projectId = 'PROJECT_ID',
model = 'gemini-2.5-flash'
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: 'us-central1',
});

const filePart = {
file_data: {
file_uri: 'gs://cloud-samples-data/generative-ai/audio/pixel.mp3',
mime_type: 'audio/mpeg',
fileData: {
fileUri: 'gs://cloud-samples-data/generative-ai/audio/pixel.mp3',
mimeType: 'audio/mpeg',
},
};
const textPart = {
Expand All @@ -37,13 +40,12 @@ async function transcript_audio(projectId = 'PROJECT_ID') {
Use speaker A, speaker B, etc. to identify speakers.`,
};

const request = {
contents: [{role: 'user', parts: [filePart, textPart]}],
};
const response = await client.models.generateContent({
model: model,
contents: [filePart, textPart],
});

const resp = await generativeModel.generateContent(request);
const contentResponse = await resp.response;
console.log(JSON.stringify(contentResponse));
console.log(response.text);
}
// [END generativeaionvertexai_gemini_audio_transcription]

Expand Down
27 changes: 15 additions & 12 deletions generative-ai/snippets/gemini-pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
// limitations under the License.

// [START generativeaionvertexai_gemini_pdf]
const {VertexAI} = require('@google-cloud/vertexai');
const {GoogleGenAI} = require('@google/genai');

/**
* TODO(developer): Update these variables before running the sample.
*/
async function analyze_pdf(projectId = 'PROJECT_ID') {
const vertexAI = new VertexAI({project: projectId, location: 'us-central1'});

const generativeModel = vertexAI.getGenerativeModel({
model: 'gemini-2.0-flash-001',
async function analyze_pdf(
projectId = 'PROJECT_ID',
model = 'gemini-2.5-flash'
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: 'us-central1',
});

const filePart = {
Expand All @@ -31,19 +34,19 @@ async function analyze_pdf(projectId = 'PROJECT_ID') {
mimeType: 'application/pdf',
},
};

const textPart = {
text: `
You are a very professional document summarization specialist.
Please summarize the given document.`,
};

const request = {
contents: [{role: 'user', parts: [filePart, textPart]}],
};
const response = await client.models.generateContent({
model: model,
contents: [filePart, textPart],
});

const resp = await generativeModel.generateContent(request);
const contentResponse = await resp.response;
console.log(JSON.stringify(contentResponse));
console.log(response.text);
}
// [END generativeaionvertexai_gemini_pdf]

Expand Down
40 changes: 22 additions & 18 deletions generative-ai/snippets/gemini-system-instruction.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@
// limitations under the License.

// [START generativeaionvertexai_gemini_system_instruction]
const {VertexAI} = require('@google-cloud/vertexai');
const {GoogleGenAI} = require('@google/genai');

/**
* TODO(developer): Update these variables before running the sample.
*/
async function set_system_instruction(projectId = 'PROJECT_ID') {
const vertexAI = new VertexAI({project: projectId, location: 'us-central1'});

const generativeModel = vertexAI.getGenerativeModel({
model: 'gemini-2.0-flash-001',
systemInstruction: {
parts: [
{text: 'You are a helpful language translator.'},
{text: 'Your mission is to translate text in English to French.'},
],
},
async function set_system_instruction(
projectId = 'PROJECT_ID',
model = 'gemini-2.5-flash'
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: 'us-central1',
});

const textPart = {
Expand All @@ -37,13 +34,20 @@ async function set_system_instruction(projectId = 'PROJECT_ID') {
Answer:`,
};

const request = {
contents: [{role: 'user', parts: [textPart]}],
};
const response = await client.models.generateContent({
model: model,
contents: [textPart],
config: {
systemInstruction: {
parts: [
{text: 'You are a helpful language translator.'},
{text: 'Your mission is to translate text in English to French.'},
],
},
},
});

const resp = await generativeModel.generateContent(request);
const contentResponse = await resp.response;
console.log(JSON.stringify(contentResponse));
console.log(response.text);
}
// [END generativeaionvertexai_gemini_system_instruction]

Expand Down
25 changes: 15 additions & 10 deletions generative-ai/snippets/gemini-text-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,29 @@
// limitations under the License.

// [START generativeaionvertexai_gemini_generate_from_text_input]
const {VertexAI} = require('@google-cloud/vertexai');

const {GoogleGenAI} = require('@google/genai');
/**
* TODO(developer): Update these variables before running the sample.
*/
async function generate_from_text_input(projectId = 'PROJECT_ID') {
const vertexAI = new VertexAI({project: projectId, location: 'us-central1'});

const generativeModel = vertexAI.getGenerativeModel({
model: 'gemini-2.0-flash-001',
async function generate_from_text_input(
projectId = 'PROJECT_ID',
model = 'gemini-2.5-flash'
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: 'us-central1',
});

const prompt =
"What's a good name for a flower shop that specializes in selling bouquets of dried flowers?";

const resp = await generativeModel.generateContent(prompt);
const contentResponse = await resp.response;
console.log(JSON.stringify(contentResponse));
const response = await client.models.generateContent({
model: model,
contents: prompt,
});

console.log(response.text);
}
// [END generativeaionvertexai_gemini_generate_from_text_input]

Expand Down
Loading
Loading