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
2 changes: 0 additions & 2 deletions genai/safety/safety-with-txt.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

'use strict';

// [START generativeaionvertexai_gemini_safety_settings]
// [START googlegenaisdk_safety_with_txt]
const {GoogleGenAI} = require('@google/genai');

Expand Down Expand Up @@ -110,7 +109,6 @@ async function generateWithSafetySettings(
}

// [END googlegenaisdk_safety_with_txt]
// [END generativeaionvertexai_gemini_safety_settings]

module.exports = {
generateWithSafetySettings,
Expand Down
2 changes: 0 additions & 2 deletions genai/text-generation/textgen-chat-stream-with-txt.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

'use strict';

// [START generativeaionvertexai_gemini_multiturn_chat_stream]
// [START googlegenaisdk_textgen_chat_stream_with_txt]
const {GoogleGenAI} = require('@google/genai');

Expand Down Expand Up @@ -49,7 +48,6 @@ async function generateText(
}

// [END googlegenaisdk_textgen_chat_stream_with_txt]
// [END generativeaionvertexai_gemini_multiturn_chat_stream]

module.exports = {
generateText,
Expand Down
5 changes: 1 addition & 4 deletions genai/text-generation/textgen-chat-with-txt.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

'use strict';

// [START generativeaionvertexai_gemini_multiturn_chat_nonstreaming]
// [START aiplatform_gemini_multiturn_chat_nonstreaming]
// [START googlegenaisdk_textgen_chat_with_txt]
const {GoogleGenAI} = require('@google/genai');

Expand Down Expand Up @@ -57,8 +55,7 @@ async function generateText(
}

// [END googlegenaisdk_textgen_chat_with_txt]
// [END aiplatform_gemini_multiturn_chat_nonstreaming]
// [END generativeaionvertexai_gemini_multiturn_chat_nonstreaming]

module.exports = {
generateText,
};
2 changes: 0 additions & 2 deletions genai/text-generation/textgen-with-mute-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

'use strict';

// [START generativeaionvertexai_gemini_single_turn_video]
// [START googlegenaisdk_textgen_with_mute_video]
const {GoogleGenAI} = require('@google/genai');

Expand Down Expand Up @@ -63,7 +62,6 @@ async function generateText(
return response.text;
}
// [END googlegenaisdk_textgen_with_mute_video]
// [END generativeaionvertexai_gemini_single_turn_video]

module.exports = {
generateText,
Expand Down
2 changes: 0 additions & 2 deletions genai/text-generation/textgen-with-txt-img.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

'use strict';

// [START generativeaionvertexai_gemini_get_started]
// [START googlegenaisdk_textgen_with_txt_img]
const {GoogleGenAI} = require('@google/genai');

Expand Down Expand Up @@ -48,7 +47,6 @@ async function generateContent(
return response.text;
}
// [END googlegenaisdk_textgen_with_txt_img]
// [END generativeaionvertexai_gemini_get_started]

module.exports = {
generateContent,
Expand Down
5 changes: 0 additions & 5 deletions genai/text-generation/textgen-with-txt-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
// limitations under the License.

'use strict';

// [START generativeaionvertexai_gemini_content]
// [START aiplatform_gemini_content]
// [START generativeaionvertexai_stream_text_basic]
// [START googlegenaisdk_textgen_with_txt_stream]
const {GoogleGenAI} = require('@google/genai');
Expand Down Expand Up @@ -47,8 +44,6 @@ async function generateContent(
}
// [END googlegenaisdk_textgen_with_txt_stream]
// [END generativeaionvertexai_stream_text_basic]
// [END aiplatform_gemini_content]
// [END generativeaionvertexai_gemini_content]

module.exports = {
generateContent,
Expand Down
5 changes: 0 additions & 5 deletions genai/text-generation/textgen-with-txt.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
// limitations under the License.

'use strict';

// [START generativeaionvertexai_gemini_content_nonstreaming]
// [START aiplatform_gemini_content_nonstreaming]
// [START generativeaionvertexai_gemini_generate_from_text_input]
// [START googlegenaisdk_textgen_with_txt]
const {GoogleGenAI} = require('@google/genai');
Expand Down Expand Up @@ -44,8 +41,6 @@ async function generateContent(
}
// [END googlegenaisdk_textgen_with_txt]
// [END generativeaionvertexai_gemini_generate_from_text_input]
// [END aiplatform_gemini_content_nonstreaming]
// [END generativeaionvertexai_gemini_content_nonstreaming]

module.exports = {
generateContent,
Expand Down
2 changes: 0 additions & 2 deletions genai/text-generation/textgen-with-video.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

'use strict';

// [START generativeaionvertexai_gemini_video_with_audio]
// [START googlegenaisdk_textgen_with_video]
const {GoogleGenAI} = require('@google/genai');

Expand Down Expand Up @@ -57,7 +56,6 @@ async function generateContent(
return response.text;
}
// [END googlegenaisdk_textgen_with_video]
// [END generativeaionvertexai_gemini_video_with_audio]

module.exports = {
generateContent,
Expand Down
55 changes: 55 additions & 0 deletions generative-ai/snippets/gemini-video-audio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2024 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.

// [START generativeaionvertexai_gemini_video_with_audio]
const {GoogleGenAI} = require('@google/genai');
/**
* TODO(developer): Update these variables before running the sample.
*/
async function analyze_video_with_audio(
projectId = 'PROJECT_ID',
model = 'gemini-2.5-flash'
) {
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: 'us-central1',
});

const filePart = {
fileData: {
fileUri: 'gs://cloud-samples-data/generative-ai/video/pixel8.mp4',
mimeType: 'video/mp4',
},
};

const textPart = {
text: `
Provide a description of the video.
The description should also contain anything important which people say in the video.`,
};

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

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

analyze_video_with_audio(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
56 changes: 56 additions & 0 deletions generative-ai/snippets/nonStreamingChat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2023 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.

// [START generativeaionvertexai_gemini_multiturn_chat_nonstreaming]
// [START aiplatform_gemini_multiturn_chat_nonstreaming]
const {GoogleGenAI} = require('@google/genai');
/**
* TODO(developer): Update these variables before running the sample.
*/
async function createNonStreamingChat(
projectId = 'PROJECT_ID',
location = 'us-central1',
model = 'gemini-2.5-flash'
) {
// Initialize client with your Cloud project and location
const client = new GoogleGenAI({
vertexai: true,
project: projectId,
location: location,
});

const chat = client.chats.create({
model: model,
});

const response1 = await chat.sendMessage({message: 'Hello'});
console.log('Chat response 1: ', response1.text);

const response2 = await chat.sendMessage({
message: 'Can you tell me a scientific fun fact?',
});
console.log('Chat response 2: ', response2.text);

const response3 = await chat.sendMessage({
message: 'How can I learn more about that?',
});
console.log('Chat response 3: ', response3.text);
}
// [END aiplatform_gemini_multiturn_chat_nonstreaming]
// [END generativeaionvertexai_gemini_multiturn_chat_nonstreaming]

createNonStreamingChat(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
60 changes: 60 additions & 0 deletions generative-ai/snippets/nonStreamingContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2023 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.

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

/**
* TODO(developer): Update these variables before running the sample.
*/
async function createNonStreamingContent(
projectId = 'PROJECT_ID',
location = 'us-central1',
model = 'gemini-2.0-flash-001'
) {
// Initialize Vertex with your Cloud project and location
const vertexAI = new VertexAI({project: projectId, location: location});

// Instantiate the model
const generativeModel = vertexAI.getGenerativeModel({
model: model,
});

const request = {
contents: [
{
role: 'user',
parts: [
{
text: 'Write a story about a magic backpack.',
},
],
},
],
};

console.log(JSON.stringify(request));

const result = await generativeModel.generateContent(request);

console.log(result.response.text);
}
// [END aiplatform_gemini_content_nonstreaming]
// [END generativeaionvertexai_gemini_content_nonstreaming]

createNonStreamingContent(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
71 changes: 71 additions & 0 deletions generative-ai/snippets/nonStreamingMultipartContent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright 2023 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.

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

/**
* TODO(developer): Update these variables before running the sample.
*/
async function createNonStreamingMultipartContent(
projectId = 'PROJECT_ID',
location = 'us-central1',
model = 'gemini-2.0-flash-001',
image = 'gs://generativeai-downloads/images/scones.jpg',
mimeType = 'image/jpeg'
) {
// Initialize Vertex with your Cloud project and location
const vertexAI = new VertexAI({project: projectId, location: location});

// Instantiate the model
const generativeVisionModel = vertexAI.getGenerativeModel({
model: model,
});

// For images, the SDK supports both Google Cloud Storage URI and base64 strings
const filePart = {
fileData: {
fileUri: image,
mimeType: mimeType,
},
};

const textPart = {
text: 'what is shown in this image?',
};

const request = {
contents: [{role: 'user', parts: [filePart, textPart]}],
};

console.log('Prompt Text:');
console.log(request.contents[0].parts[1].text);

console.log('Non-Streaming Response Text:');

// Generate a response
const response = await generativeVisionModel.generateContent(request);

// Select the text from the response
const fullTextResponse =
response.response.candidates[0].content.parts[0].text;

console.log(fullTextResponse);
}
// [END generativeaionvertexai_gemini_get_started]

createNonStreamingMultipartContent(...process.argv.slice(2)).catch(err => {
console.error(err.message);
process.exitCode = 1;
});
Loading
Loading