diff --git a/genai/count-tokens/counttoken-compute-with-txt.js b/genai/count-tokens/counttoken-compute-with-txt.js index fd68a462e8..241e2f6005 100644 --- a/genai/count-tokens/counttoken-compute-with-txt.js +++ b/genai/count-tokens/counttoken-compute-with-txt.js @@ -24,14 +24,14 @@ async function countTokens( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, httpOptions: {apiVersion: 'v1'}, }); - const response = await ai.models.computeTokens({ + const response = await client.models.computeTokens({ model: 'gemini-2.5-flash', contents: "What's the longest word in the English language?", }); diff --git a/genai/count-tokens/counttoken-resp-with-txt.js b/genai/count-tokens/counttoken-resp-with-txt.js index c8cf4fe6cc..399fa5a5e4 100644 --- a/genai/count-tokens/counttoken-resp-with-txt.js +++ b/genai/count-tokens/counttoken-resp-with-txt.js @@ -24,14 +24,14 @@ async function countTokens( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, httpOptions: {apiVersion: 'v1'}, }); - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-flash', contents: 'Why is the sky blue?', }); diff --git a/genai/count-tokens/counttoken-with-txt-vid.js b/genai/count-tokens/counttoken-with-txt-vid.js index 766de4b00b..02b8be38fe 100644 --- a/genai/count-tokens/counttoken-with-txt-vid.js +++ b/genai/count-tokens/counttoken-with-txt-vid.js @@ -24,7 +24,7 @@ async function countTokens( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, @@ -37,7 +37,7 @@ async function countTokens( }, }; - const response = await ai.models.countTokens({ + const response = await client.models.countTokens({ model: 'gemini-2.5-flash', contents: [video, 'Provide a description of the video.'], }); diff --git a/genai/count-tokens/counttoken-with-txt.js b/genai/count-tokens/counttoken-with-txt.js index 111f7148cd..f68397aaa3 100644 --- a/genai/count-tokens/counttoken-with-txt.js +++ b/genai/count-tokens/counttoken-with-txt.js @@ -24,13 +24,13 @@ async function countTokens( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, }); - const response = await ai.models.countTokens({ + const response = await client.models.countTokens({ model: 'gemini-2.5-flash', contents: 'What is the highest mountain in Africa?', }); diff --git a/genai/image-generation/imggen-mmflash-with-txt.js b/genai/image-generation/imggen-mmflash-with-txt.js index 054a7f72d5..44c2ef0397 100644 --- a/genai/image-generation/imggen-mmflash-with-txt.js +++ b/genai/image-generation/imggen-mmflash-with-txt.js @@ -26,14 +26,14 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, }); - const response = await ai.models.generateContentStream({ - model: 'gemini-2.0-flash-exp', + const response = await client.models.generateContentStream({ + model: 'gemini-2.5-flash-image', contents: 'Generate an image of the Eiffel tower with fireworks in the background.', config: { diff --git a/genai/package.json b/genai/package.json index d04ae788d4..9d94f3811b 100644 --- a/genai/package.json +++ b/genai/package.json @@ -13,7 +13,7 @@ "test": "c8 mocha -p -j 2 --timeout 2400000 test/*.test.js test/**/*.test.js" }, "dependencies": { - "@google/genai": "1.12.0", + "@google/genai": "1.20.0", "axios": "^1.6.2", "luxon": "^3.7.1", "supertest": "^7.0.0" diff --git a/genai/test/imggen-mmflash-with-txt.test.js b/genai/test/imggen-mmflash-with-txt.test.js index 44f109b269..87cd1b8238 100644 --- a/genai/test/imggen-mmflash-with-txt.test.js +++ b/genai/test/imggen-mmflash-with-txt.test.js @@ -18,16 +18,20 @@ const {assert} = require('chai'); const {describe, it} = require('mocha'); const projectId = process.env.CAIP_PROJECT_ID; +const location = 'global'; + const sample = require('../image-generation/imggen-mmflash-with-txt.js'); const {delay} = require('./util'); describe('imggen-mmflash-with-txt', async () => { it('should generate images from a text prompt', async function () { this.timeout(180000); - this.retries(10); + this.retries(5); await delay(this.test); - const generatedFileNames = await sample.generateContent(projectId); - assert(Array.isArray(generatedFileNames)); + const generatedFileNames = await sample.generateContent( + projectId, + location + ); assert(generatedFileNames.length > 0); }); }); diff --git a/genai/text-generation/textgen-code-with-pdf.js b/genai/text-generation/textgen-code-with-pdf.js index 22a29d0393..820227711d 100644 --- a/genai/text-generation/textgen-code-with-pdf.js +++ b/genai/text-generation/textgen-code-with-pdf.js @@ -24,7 +24,7 @@ async function generateText( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, @@ -46,7 +46,7 @@ async function generateText( }, ]; - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-flash', contents: contents, }); diff --git a/genai/text-generation/textgen-sys-instr-with-txt.js b/genai/text-generation/textgen-sys-instr-with-txt.js index 309a5f630b..f61e9f0d02 100644 --- a/genai/text-generation/textgen-sys-instr-with-txt.js +++ b/genai/text-generation/textgen-sys-instr-with-txt.js @@ -24,7 +24,7 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, @@ -35,7 +35,7 @@ async function generateContent( Answer: `; - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-flash', contents: prompt, config: { diff --git a/genai/text-generation/textgen-with-multi-img.js b/genai/text-generation/textgen-with-multi-img.js index 8bd750f99a..1aeda15c52 100644 --- a/genai/text-generation/textgen-with-multi-img.js +++ b/genai/text-generation/textgen-with-multi-img.js @@ -24,7 +24,7 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, @@ -44,7 +44,7 @@ async function generateContent( }, }; - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-flash', contents: [ image1, diff --git a/genai/text-generation/textgen-with-multi-local-img.js b/genai/text-generation/textgen-with-multi-local-img.js index 855c875222..6a2092623a 100644 --- a/genai/text-generation/textgen-with-multi-local-img.js +++ b/genai/text-generation/textgen-with-multi-local-img.js @@ -32,7 +32,7 @@ async function generateContent( imagePath1, imagePath2 ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, @@ -42,7 +42,7 @@ async function generateContent( const image1 = loadImageAsBase64(imagePath1); const image2 = loadImageAsBase64(imagePath2); - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-flash', contents: [ { diff --git a/genai/text-generation/textgen-with-txt-img.js b/genai/text-generation/textgen-with-txt-img.js index 3799118e60..29f86f4b6e 100644 --- a/genai/text-generation/textgen-with-txt-img.js +++ b/genai/text-generation/textgen-with-txt-img.js @@ -24,7 +24,7 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, @@ -37,7 +37,7 @@ async function generateContent( }, }; - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-flash', contents: [image, 'What is shown in this image?'], }); diff --git a/genai/text-generation/textgen-with-txt-routing.js b/genai/text-generation/textgen-with-txt-routing.js index 593110f69d..c3976d702e 100644 --- a/genai/text-generation/textgen-with-txt-routing.js +++ b/genai/text-generation/textgen-with-txt-routing.js @@ -25,7 +25,7 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, @@ -37,7 +37,7 @@ async function generateContent( }, }; - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'model-optimizer-exp-04-09', contents: 'How does AI work?', config: generateContentConfig, diff --git a/genai/text-generation/textgen-with-txt-stream.js b/genai/text-generation/textgen-with-txt-stream.js index be8e69d595..44667a7b4f 100644 --- a/genai/text-generation/textgen-with-txt-stream.js +++ b/genai/text-generation/textgen-with-txt-stream.js @@ -24,13 +24,13 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, }); - const response = await ai.models.generateContentStream({ + const response = await client.models.generateContentStream({ model: 'gemini-2.5-flash', contents: 'Why is the sky blue?', }); diff --git a/genai/text-generation/textgen-with-txt.js b/genai/text-generation/textgen-with-txt.js index 9325b3dd4f..ba3294ac75 100644 --- a/genai/text-generation/textgen-with-txt.js +++ b/genai/text-generation/textgen-with-txt.js @@ -24,13 +24,13 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, }); - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-flash', contents: 'How does AI work?', }); diff --git a/genai/text-generation/textgen-with-video.js b/genai/text-generation/textgen-with-video.js index ee7288bd63..76b552facb 100644 --- a/genai/text-generation/textgen-with-video.js +++ b/genai/text-generation/textgen-with-video.js @@ -24,7 +24,7 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, @@ -43,7 +43,7 @@ async function generateContent( }, }; - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-flash', contents: [video, prompt], }); diff --git a/genai/tools/tools-code-exec-with-txt.js b/genai/tools/tools-code-exec-with-txt.js index 0d0b883ac8..6aaeb0ec81 100644 --- a/genai/tools/tools-code-exec-with-txt.js +++ b/genai/tools/tools-code-exec-with-txt.js @@ -24,13 +24,13 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, }); - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: 'gemini-2.5-flash', contents: 'What is the sum of the first 50 prime numbers? Generate and run code for the calculation, and make sure you get all 50.', diff --git a/genai/tools/tools-func-desc-with-txt.js b/genai/tools/tools-func-desc-with-txt.js index b416016ef6..b3f38f1c86 100644 --- a/genai/tools/tools-func-desc-with-txt.js +++ b/genai/tools/tools-func-desc-with-txt.js @@ -24,7 +24,7 @@ async function generateContent( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { - const ai = new GoogleGenAI({ + const client = new GoogleGenAI({ vertexai: true, project: projectId, location: location, @@ -73,7 +73,7 @@ async function generateContent( const MODEL_NAME = 'gemini-2.5-flash'; - const response = await ai.models.generateContent({ + const response = await client.models.generateContent({ model: MODEL_NAME, contents: prompt, config: {