diff --git a/genai/count-tokens/counttoken-resp-with-txt.js b/genai/count-tokens/counttoken-resp-with-txt.js index 399fa5a5e41..f19fbe2e00e 100644 --- a/genai/count-tokens/counttoken-resp-with-txt.js +++ b/genai/count-tokens/counttoken-resp-with-txt.js @@ -13,7 +13,7 @@ // limitations under the License. 'use strict'; - +// [START generativeaionvertexai_gemini_token_count] // [START googlegenaisdk_counttoken_resp_with_txt] const {GoogleGenAI} = require('@google/genai'); @@ -41,6 +41,7 @@ async function countTokens( return response.usageMetadata; } // [END googlegenaisdk_counttoken_resp_with_txt] +// [END generativeaionvertexai_gemini_token_count] module.exports = { countTokens, diff --git a/genai/count-tokens/counttoken-with-txt-vid.js b/genai/count-tokens/counttoken-with-txt-vid.js index 02b8be38fe9..c8ef18fcc8d 100644 --- a/genai/count-tokens/counttoken-with-txt-vid.js +++ b/genai/count-tokens/counttoken-with-txt-vid.js @@ -14,6 +14,7 @@ 'use strict'; +// [START generativeaionvertexai_gemini_token_count_advanced] // [START googlegenaisdk_counttoken_with_txt_vid] const {GoogleGenAI} = require('@google/genai'); @@ -47,6 +48,7 @@ async function countTokens( return response.totalTokens; } // [END googlegenaisdk_counttoken_with_txt_vid] +// [END generativeaionvertexai_gemini_token_count_advanced] module.exports = { countTokens, diff --git a/genai/text-generation/textgen-sys-instr-with-txt.js b/genai/text-generation/textgen-sys-instr-with-txt.js index f61e9f0d020..c5d636171da 100644 --- a/genai/text-generation/textgen-sys-instr-with-txt.js +++ b/genai/text-generation/textgen-sys-instr-with-txt.js @@ -14,6 +14,8 @@ 'use strict'; +// [START generativeaionvertexai_gemini_translate] +// [START generativeaionvertexai_gemini_system_instruction] // [START googlegenaisdk_textgen_sys_instr_with_txt] const {GoogleGenAI} = require('@google/genai'); @@ -51,6 +53,8 @@ async function generateContent( return response.text; } // [END googlegenaisdk_textgen_sys_instr_with_txt] +// [END generativeaionvertexai_gemini_system_instruction] +// [END generativeaionvertexai_gemini_translate] module.exports = { generateContent, diff --git a/genai/text-generation/textgen-transcript-with-gcs-audio.js b/genai/text-generation/textgen-transcript-with-gcs-audio.js index 4c6daad8931..cfff189f38f 100644 --- a/genai/text-generation/textgen-transcript-with-gcs-audio.js +++ b/genai/text-generation/textgen-transcript-with-gcs-audio.js @@ -13,7 +13,7 @@ // limitations under the License. 'use strict'; - +// [START generativeaionvertexai_gemini_audio_transcription] // [START googlegenaisdk_textgen_transcript_with_gcs_audio] const {GoogleGenAI} = require('@google/genai'); @@ -63,6 +63,7 @@ async function generateText( } // [END googlegenaisdk_textgen_transcript_with_gcs_audio] +// [END generativeaionvertexai_gemini_audio_transcription] module.exports = { generateText, diff --git a/genai/text-generation/textgen-with-gcs-audio.js b/genai/text-generation/textgen-with-gcs-audio.js index 67a28619fa7..a3c56d2fedd 100644 --- a/genai/text-generation/textgen-with-gcs-audio.js +++ b/genai/text-generation/textgen-with-gcs-audio.js @@ -13,7 +13,7 @@ // limitations under the License. 'use strict'; - +// [START generativeaionvertexai_gemini_audio_summarization] // [START googlegenaisdk_textgen_with_gcs_audio] const {GoogleGenAI} = require('@google/genai'); @@ -55,6 +55,7 @@ async function generateText( return response.text; } // [END googlegenaisdk_textgen_with_gcs_audio] +// [END generativeaionvertexai_gemini_audio_summarization] module.exports = { generateText, diff --git a/genai/text-generation/textgen-with-pdf.js b/genai/text-generation/textgen-with-pdf.js index 14a0f87fb1c..1f052ee716c 100644 --- a/genai/text-generation/textgen-with-pdf.js +++ b/genai/text-generation/textgen-with-pdf.js @@ -13,7 +13,7 @@ // limitations under the License. 'use strict'; - +// [START generativeaionvertexai_gemini_pdf] // [START googlegenaisdk_textgen_with_pdf] const {GoogleGenAI} = require('@google/genai'); @@ -59,6 +59,7 @@ async function generateText( } // [END googlegenaisdk_textgen_with_pdf] +// [END generativeaionvertexai_gemini_pdf] module.exports = { generateText, diff --git a/genai/text-generation/textgen-with-txt-stream.js b/genai/text-generation/textgen-with-txt-stream.js index 44667a7b4f4..9a0b9b7ae50 100644 --- a/genai/text-generation/textgen-with-txt-stream.js +++ b/genai/text-generation/textgen-with-txt-stream.js @@ -13,7 +13,7 @@ // limitations under the License. 'use strict'; - +// [START generativeaionvertexai_stream_text_basic] // [START googlegenaisdk_textgen_with_txt_stream] const {GoogleGenAI} = require('@google/genai'); @@ -43,6 +43,7 @@ async function generateContent( return response_text; } // [END googlegenaisdk_textgen_with_txt_stream] +// [END generativeaionvertexai_stream_text_basic] module.exports = { generateContent, diff --git a/genai/text-generation/textgen-with-txt.js b/genai/text-generation/textgen-with-txt.js index a81767e664f..3c62081f184 100644 --- a/genai/text-generation/textgen-with-txt.js +++ b/genai/text-generation/textgen-with-txt.js @@ -13,7 +13,7 @@ // limitations under the License. 'use strict'; - +// [START generativeaionvertexai_gemini_generate_from_text_input] // [START googlegenaisdk_textgen_with_txt] const {GoogleGenAI} = require('@google/genai'); @@ -40,6 +40,7 @@ async function generateContent( return response.text; } // [END googlegenaisdk_textgen_with_txt] +// [END generativeaionvertexai_gemini_generate_from_text_input] module.exports = { generateContent, diff --git a/genai/tools/tools-func-desc-with-txt.js b/genai/tools/tools-func-desc-with-txt.js index f9b3c550361..1896c45aedc 100644 --- a/genai/tools/tools-func-desc-with-txt.js +++ b/genai/tools/tools-func-desc-with-txt.js @@ -14,6 +14,7 @@ 'use strict'; +// [START generativeaionvertexai_function_calling_advanced] // [START googlegenaisdk_tools_func_desc_with_txt] const {GoogleGenAI, Type} = require('@google/genai'); @@ -99,6 +100,7 @@ async function generateFunctionDesc( } // [END googlegenaisdk_tools_func_desc_with_txt] +// [END generativeaionvertexai_function_calling_advanced] module.exports = { generateFunctionDesc, diff --git a/generative-ai/snippets/count-tokens/countTokens.js b/generative-ai/snippets/count-tokens/countTokens.js deleted file mode 100644 index b1d79966b8e..00000000000 --- a/generative-ai/snippets/count-tokens/countTokens.js +++ /dev/null @@ -1,59 +0,0 @@ -// 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_token_count] -const {GoogleGenAI} = require('@google/genai'); - -/** - * TODO(developer): Update these variables before running the sample. - */ -async function countTokens( - projectId = 'PROJECT_ID', - location = 'us-central1', - model = 'gemini-2.5-flash' -) { - // Initialize the client with your Cloud project and location - const client = new GoogleGenAI({ - vertexai: true, - project: projectId, - location: location, - }); - - const contents = [ - {role: 'user', parts: [{text: 'How are you doing today?'}]}, - ]; - - // Prompt tokens count - const countTokensResp = await client.models.countTokens({ - model: model, - contents: contents, - }); - console.log('Prompt tokens count: ', countTokensResp); - - // Send text to gemini - const result = await client.models.generateContent({ - model: model, - contents: contents, - }); - - // Response tokens count - const usageMetadata = result.usageMetadata; - console.log('Response tokens count: ', usageMetadata); -} -// [END generativeaionvertexai_gemini_token_count] - -countTokens(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/count-tokens/countTokensAdvanced.js b/generative-ai/snippets/count-tokens/countTokensAdvanced.js deleted file mode 100644 index 9de2ff43a11..00000000000 --- a/generative-ai/snippets/count-tokens/countTokensAdvanced.js +++ /dev/null @@ -1,71 +0,0 @@ -// 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_token_count_advanced] -const {GoogleGenAI} = require('@google/genai'); -/** - * TODO(developer): Update these variables before running the sample. - */ -async function countTokens( - 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 contents = [ - { - role: 'user', - parts: [ - { - fileData: { - fileUri: 'gs://cloud-samples-data/generative-ai/video/pixel8.mp4', - mimeType: 'video/mp4', - }, - }, - {text: 'Provide a description of the video.'}, - ], - }, - ]; - - const countTokensResp = await client.models.countTokens({ - model: model, - contents: contents, - }); - - console.log('Prompt Token Count:', countTokensResp.totalTokens); - - // Send text to Gemini - const result = await client.models.generateContent({ - model: model, - contents: contents, - }); - - const usageMetadata = result.usageMetadata; - - console.log('Prompt Token Count:', usageMetadata.promptTokenCount); - console.log('Candidates Token Count:', usageMetadata.candidatesTokenCount); - console.log('Total Token Count:', usageMetadata.totalTokenCount); -} -// [END generativeaionvertexai_gemini_token_count_advanced] - -countTokens(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/function-calling/functionCallingAdvanced.js b/generative-ai/snippets/function-calling/functionCallingAdvanced.js deleted file mode 100644 index 72fcfa43fc4..00000000000 --- a/generative-ai/snippets/function-calling/functionCallingAdvanced.js +++ /dev/null @@ -1,85 +0,0 @@ -// 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_function_calling_advanced] -const {GoogleGenAI} = require('@google/genai'); - -const tools = [ - { - functionDeclarations: [ - { - name: 'get_product_sku', - description: 'Get the available inventory for Google products', - parameters: { - type: 'OBJECT', - properties: { - productName: {type: 'STRING'}, - }, - }, - }, - { - name: 'get_store_location', - description: 'Get the location of the closest store', - parameters: { - type: 'OBJECT', - properties: { - location: {type: 'STRING'}, - }, - }, - }, - ], - }, -]; - -const toolConfig = { - functionCallingConfig: { - mode: 'ANY', - allowedFunctionNames: ['get_product_sku'], - }, -}; - -/** - * TODO(developer): Update these variables before running the sample. - */ -async function functionCallingAdvanced( - 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 result = await client.models.generateContent({ - model: model, - contents: 'Do you have the White Pixel 8 Pro 128GB in stock in the US?', - config: { - tools: tools, - toolConfig: toolConfig, - temperature: 0.95, - topP: 1.0, - maxOutputTokens: 8192, - }, - }); - console.log(JSON.stringify(result.functionCalls)); -} -// [END generativeaionvertexai_function_calling_advanced] - -functionCallingAdvanced(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/gemini-audio-summarization.js b/generative-ai/snippets/gemini-audio-summarization.js deleted file mode 100644 index 067a335954d..00000000000 --- a/generative-ai/snippets/gemini-audio-summarization.js +++ /dev/null @@ -1,55 +0,0 @@ -// 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_audio_summarization] -const {GoogleGenAI} = require('@google/genai'); -/** - * TODO(developer): Update these variables before running the sample. - */ -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 = { - fileData: { - fileUri: 'gs://cloud-samples-data/generative-ai/audio/pixel.mp3', - mimeType: 'audio/mpeg', - }, - }; - const textPart = { - text: ` - Please provide a summary for the audio. - Provide chapter titles with timestamps, be concise and short, no need to provide chapter summaries. - Do not make up any information that is not part of the audio and do not be verbose.`, - }; - - const response = await client.models.generateContent({ - model: model, - contents: [filePart, textPart], - }); - - console.log(response.text); -} -// [END generativeaionvertexai_gemini_audio_summarization] - -summarize_audio(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/gemini-audio-transcription.js b/generative-ai/snippets/gemini-audio-transcription.js deleted file mode 100644 index 568791ea1ef..00000000000 --- a/generative-ai/snippets/gemini-audio-transcription.js +++ /dev/null @@ -1,55 +0,0 @@ -// 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_audio_transcription] -const {GoogleGenAI} = require('@google/genai'); - -/** - * TODO(developer): Update these variables before running the sample. - */ -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 = { - fileData: { - fileUri: 'gs://cloud-samples-data/generative-ai/audio/pixel.mp3', - mimeType: 'audio/mpeg', - }, - }; - const textPart = { - text: ` - Can you transcribe this interview, in the format of timecode, speaker, caption? - Use speaker A, speaker B, etc. to identify speakers.`, - }; - - const response = await client.models.generateContent({ - model: model, - contents: [filePart, textPart], - }); - - console.log(response.text); -} -// [END generativeaionvertexai_gemini_audio_transcription] - -transcript_audio(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/gemini-pdf.js b/generative-ai/snippets/gemini-pdf.js deleted file mode 100644 index bc9c6ecae58..00000000000 --- a/generative-ai/snippets/gemini-pdf.js +++ /dev/null @@ -1,56 +0,0 @@ -// 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_pdf] -const {GoogleGenAI} = require('@google/genai'); - -/** - * TODO(developer): Update these variables before running the sample. - */ -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 = { - fileData: { - fileUri: 'gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf', - mimeType: 'application/pdf', - }, - }; - - const textPart = { - text: ` - You are a very professional document summarization specialist. - Please summarize the given document.`, - }; - - const response = await client.models.generateContent({ - model: model, - contents: [filePart, textPart], - }); - - console.log(response.text); -} -// [END generativeaionvertexai_gemini_pdf] - -analyze_pdf(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/gemini-system-instruction.js b/generative-ai/snippets/gemini-system-instruction.js deleted file mode 100644 index 5d9f845b918..00000000000 --- a/generative-ai/snippets/gemini-system-instruction.js +++ /dev/null @@ -1,57 +0,0 @@ -// 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_system_instruction] -const {GoogleGenAI} = require('@google/genai'); - -/** - * TODO(developer): Update these variables before running the sample. - */ -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 = { - text: ` - User input: I like bagels. - Answer:`, - }; - - 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.'}, - ], - }, - }, - }); - - console.log(response.text); -} -// [END generativeaionvertexai_gemini_system_instruction] - -set_system_instruction(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/gemini-text-input.js b/generative-ai/snippets/gemini-text-input.js deleted file mode 100644 index 44b49058948..00000000000 --- a/generative-ai/snippets/gemini-text-input.js +++ /dev/null @@ -1,45 +0,0 @@ -// 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_generate_from_text_input] -const {GoogleGenAI} = require('@google/genai'); -/** - * TODO(developer): Update these variables before running the sample. - */ -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 response = await client.models.generateContent({ - model: model, - contents: prompt, - }); - - console.log(response.text); -} -// [END generativeaionvertexai_gemini_generate_from_text_input] - -generate_from_text_input(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/gemini-translate.js b/generative-ai/snippets/gemini-translate.js deleted file mode 100644 index 6a87019565e..00000000000 --- a/generative-ai/snippets/gemini-translate.js +++ /dev/null @@ -1,88 +0,0 @@ -// 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. - -'use strict'; -// [START generativeaionvertexai_gemini_translate] -const {GoogleGenAI} = require('@google/genai'); - -/** - * TODO(developer): Update these variables before running the sample. - */ -async function geminiTranslation( - projectId = 'PROJECT_ID', - location = 'us-central1', - model = 'gemini-2.5-flash' -) { - const client = new GoogleGenAI({ - vertexai: true, - project: projectId, - location, - }); - - // The text to be translated. - const text = 'Hello! How are you doing today?'; - // The language code of the target language. Defaults to "fr" (*French). - // Available language codes: - // https://cloud.google.com/translate/docs/languages#neural_machine_translation_model - const targetLanguageCode = 'fr'; - - const textPart = { - text: ` - User input:${text} - Answer:`, - }; - - const content = `Your mission is to translate text in English to ${targetLanguageCode}`; - - const response = await client.models.generateContent({ - model: model, - contents: [textPart], - config: { - maxOutputTokens: 2048, - temperature: 0.4, - topP: 1, - topK: 32, - systemInstruction: { - parts: [{text: content}], - }, - safetySettings: [ - { - category: 'HARM_CATEGORY_HATE_SPEECH', - threshold: 'BLOCK_MEDIUM_AND_ABOVE', - }, - { - category: 'HARM_CATEGORY_DANGEROUS_CONTENT', - threshold: 'BLOCK_MEDIUM_AND_ABOVE', - }, - { - category: 'HARM_CATEGORY_SEXUALLY_EXPLICIT', - threshold: 'BLOCK_MEDIUM_AND_ABOVE', - }, - { - category: 'HARM_CATEGORY_HARASSMENT', - threshold: 'BLOCK_MEDIUM_AND_ABOVE', - }, - ], - }, - }); - - console.log(response.text); - return response; - // [END generativeaionvertexai_gemini_translate] -} - -geminiTranslation(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/inference/streamTextBasic.js b/generative-ai/snippets/inference/streamTextBasic.js deleted file mode 100644 index a4dc0ae8989..00000000000 --- a/generative-ai/snippets/inference/streamTextBasic.js +++ /dev/null @@ -1,60 +0,0 @@ -// 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_stream_text_basic] -const {GoogleGenAI} = require('@google/genai'); - -/** - * TODO(developer): Update these variables before running the sample. - */ - -async function generateContent( - 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 request = { - model: model, - contents: [ - { - role: 'user', - parts: [ - { - text: 'Write a story about a magic backpack.', - }, - ], - }, - ], - }; - console.log(JSON.stringify(request)); - - const responseStream = await client.models.generateContentStream(request); - - for await (const chunk of responseStream) { - console.log(chunk.text); - } -} -// [END generativeaionvertexai_stream_text_basic] - -generateContent(...process.argv.slice(2)).catch(err => { - console.error(err.message); - process.exitCode = 1; -}); diff --git a/generative-ai/snippets/test/count-tokens/countTokens.test.js b/generative-ai/snippets/test/count-tokens/countTokens.test.js deleted file mode 100644 index 76c09ad3e6f..00000000000 --- a/generative-ai/snippets/test/count-tokens/countTokens.test.js +++ /dev/null @@ -1,43 +0,0 @@ -// 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. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const projectId = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; -const model = 'gemini-2.5-flash'; - -describe('Count tokens', async () => { - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_LOCATION'; - // const model = 'gemini-2.5-flash'; - - it('should count tokens', async () => { - const output = execSync( - `node ./count-tokens/countTokens.js ${projectId} ${location} ${model}` - ); - - // Expect 6 tokens - assert(output.match('totalTokens: 6')); - }); -}); diff --git a/generative-ai/snippets/test/count-tokens/countTokensAdvanced.test.js b/generative-ai/snippets/test/count-tokens/countTokensAdvanced.test.js deleted file mode 100644 index e3b8d54da62..00000000000 --- a/generative-ai/snippets/test/count-tokens/countTokensAdvanced.test.js +++ /dev/null @@ -1,43 +0,0 @@ -// 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. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const projectId = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; -const model = 'gemini-2.5-flash'; - -describe('Count tokens advanced', async () => { - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_LOCATION'; - // const model = 'gemini-2.5-flash'; - - it('should count tokens in a multimodal prompt', async () => { - const output = execSync( - `node ./count-tokens/countTokensAdvanced.js ${projectId} ${location} ${model}` - ); - - assert(output.match(/Prompt Token Count: \d+/)); - assert(output.match(/Total Token Count: \d+/)); - }); -}); diff --git a/generative-ai/snippets/test/function-calling/functionCallingAdvanced.test.js b/generative-ai/snippets/test/function-calling/functionCallingAdvanced.test.js deleted file mode 100644 index 26ff2a79d91..00000000000 --- a/generative-ai/snippets/test/function-calling/functionCallingAdvanced.test.js +++ /dev/null @@ -1,43 +0,0 @@ -// 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. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const projectId = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION; -const model = 'gemini-2.5-flash'; - -describe('Generative AI Function Calling Advanced', () => { - /** - * TODO(developer): Uncomment these variables before running the sample.\ - * (Not necessary if passing values as arguments) - */ - // const projectId = 'YOUR_PROJECT_ID'; - // const location = 'YOUR_LOCATION'; - // const model = 'gemini-2.5-flash'; - - it('should define multiple functions and have the model invoke the specified one', async () => { - const output = execSync( - `node ./function-calling/functionCallingAdvanced.js ${projectId} ${location} ${model}` - ); - - // Assert that the response is what we expect - assert(output.match(/get_product_sku/)); - }); -}); diff --git a/generative-ai/snippets/test/gemini-audio-summarization.test.js b/generative-ai/snippets/test/gemini-audio-summarization.test.js deleted file mode 100644 index 6bff587554c..00000000000 --- a/generative-ai/snippets/test/gemini-audio-summarization.test.js +++ /dev/null @@ -1,33 +0,0 @@ -// 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. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const projectId = process.env.CAIP_PROJECT_ID; -const model = 'gemini-2.5-flash'; - -describe('Summarize audio', async () => { - it('should summarize audio', async () => { - const output = execSync( - `node ./gemini-audio-summarization.js ${projectId} ${model}` - ); - - assert(output.length > 0); - }); -}); diff --git a/generative-ai/snippets/test/gemini-audio-transcription.test.js b/generative-ai/snippets/test/gemini-audio-transcription.test.js deleted file mode 100644 index 17499cd9d8a..00000000000 --- a/generative-ai/snippets/test/gemini-audio-transcription.test.js +++ /dev/null @@ -1,33 +0,0 @@ -// 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. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const projectId = process.env.CAIP_PROJECT_ID; -const model = 'gemini-2.5-flash'; - -describe('Transcript audio', async () => { - it('should transcript audio', async () => { - const output = execSync( - `node ./gemini-audio-transcription.js ${projectId} ${model}` - ); - - assert(output.length > 0); - }); -}); diff --git a/generative-ai/snippets/test/gemini-pdf.test.js b/generative-ai/snippets/test/gemini-pdf.test.js deleted file mode 100644 index ca97f9609ea..00000000000 --- a/generative-ai/snippets/test/gemini-pdf.test.js +++ /dev/null @@ -1,31 +0,0 @@ -// 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. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const projectId = process.env.CAIP_PROJECT_ID; -const model = 'gemini-2.5-flash'; - -describe('Analyze PDF document', async () => { - it('should analyze PDF document', async () => { - const output = execSync(`node ./gemini-pdf.js ${projectId} ${model}`); - - assert(output.length > 0); - }); -}); diff --git a/generative-ai/snippets/test/gemini-system-instruction.test.js b/generative-ai/snippets/test/gemini-system-instruction.test.js deleted file mode 100644 index 876f06c1138..00000000000 --- a/generative-ai/snippets/test/gemini-system-instruction.test.js +++ /dev/null @@ -1,33 +0,0 @@ -// 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. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const projectId = process.env.CAIP_PROJECT_ID; -const model = 'gemini-2.5-flash'; - -describe('Set system instruction', async () => { - it('should set system instruction', async () => { - const output = execSync( - `node ./gemini-system-instruction.js ${projectId} ${model}` - ); - - assert(output.length > 0); - }); -}); diff --git a/generative-ai/snippets/test/gemini-text-input.test.js b/generative-ai/snippets/test/gemini-text-input.test.js deleted file mode 100644 index 80caa063dcd..00000000000 --- a/generative-ai/snippets/test/gemini-text-input.test.js +++ /dev/null @@ -1,33 +0,0 @@ -// 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. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const projectId = process.env.CAIP_PROJECT_ID; -const model = 'gemini-2.5-flash'; - -describe('Get store name ideas from text input prompt', async () => { - it('should get store name ideas from text input prompt', async () => { - const output = execSync( - `node ./gemini-text-input.js ${projectId} ${model}` - ); - - assert(output.length > 0); - }); -}); diff --git a/generative-ai/snippets/test/gemini-translate.test.js b/generative-ai/snippets/test/gemini-translate.test.js deleted file mode 100644 index b319a1e7ef9..00000000000 --- a/generative-ai/snippets/test/gemini-translate.test.js +++ /dev/null @@ -1,34 +0,0 @@ -// 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. - -'use strict'; - -const assert = require('node:assert/strict'); -const {describe, it} = require('mocha'); -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const projectId = process.env.CAIP_PROJECT_ID; -const location = process.env.LOCATION || 'us-central1'; -const model = 'gemini-2.5-flash'; - -describe('Gemini translate', () => { - it('should translate text', async () => { - const response = execSync( - `node ./gemini-translate.js ${projectId} ${location} ${model}` - ); - - assert(JSON.stringify(response).match(/Bonjour/)); - }); -}); diff --git a/generative-ai/snippets/test/inference/streamTextBasic.test.js b/generative-ai/snippets/test/inference/streamTextBasic.test.js deleted file mode 100644 index b3f2b1eea74..00000000000 --- a/generative-ai/snippets/test/inference/streamTextBasic.test.js +++ /dev/null @@ -1,33 +0,0 @@ -// 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. - -'use strict'; - -const {assert} = require('chai'); -const {describe, it} = require('mocha'); -const cp = require('child_process'); -const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'}); - -const projectId = process.env.GOOGLE_SAMPLES_PROJECT; -const location = process.env.LOCATION; -const model = 'gemini-2.5-flash'; - -describe('Generative AI Basic Text Inference Streaming', () => { - it('should create a generative text model and infer text from a prompt, streaming the results', async () => { - const output = execSync( - `node ./inference/streamTextBasic.js ${projectId} ${location} ${model}` - ); - assert(output.length > 0); - }); -});