diff --git a/genai/image-generation/imggen-mmflash-edit-img-with-txt-img.js b/genai/image-generation/imggen-mmflash-edit-img-with-txt-img.js new file mode 100644 index 0000000000..5ea12a431b --- /dev/null +++ b/genai/image-generation/imggen-mmflash-edit-img-with-txt-img.js @@ -0,0 +1,70 @@ +// 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_imggen_mmflash_edit_img_with_txt_img] +const fs = require('fs'); +const {GoogleGenAI, Modality} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = + process.env.GOOGLE_CLOUD_LOCATION || 'us-central1'; + +const FILE_NAME = 'test-data/example-image-eiffel-tower.png'; + +async function generateImage( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const image = fs.readFileSync(FILE_NAME); + + const response = await client.models.generateContent({ + model: 'gemini-2.5-flash-image', + contents: [image, 'Edit this image to make it look like a cartoon'], + config: { + responseModalities: [Modality.TEXT, Modality.IMAGE], + }, + }); + + for (const part of response.candidates[0].content.parts) { + if (part.text) { + console.log(`${part.text}`); + } else if (part.inlineData) { + const outputDir = 'output-folder'; + if (!fs.existsSync(outputDir)) { + fs.mkdirSync(outputDir, {recursive: true}); + } + const imageBytes = Buffer.from(part.inlineData.data, 'base64'); + const filename = `${outputDir}/bw-example-image.png`; + fs.writeFileSync(filename, imageBytes); + } + } + + // Example response: + // Okay, I will edit this image to give it a cartoonish style, with bolder outlines, simplified details, and more vibrant colors. + return response; +} + +// [END googlegenaisdk_imggen_mmflash_edit_img_with_txt_img] + +module.exports = { + generateImage, +}; diff --git a/genai/image-generation/imggen-mmflash-locale-aware-with-txt.js b/genai/image-generation/imggen-mmflash-locale-aware-with-txt.js new file mode 100644 index 0000000000..e16876b6b7 --- /dev/null +++ b/genai/image-generation/imggen-mmflash-locale-aware-with-txt.js @@ -0,0 +1,71 @@ +// 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_imggen_mmflash_locale_aware_with_txt] +const fs = require('fs'); +const {GoogleGenAI, Modality} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = + process.env.GOOGLE_CLOUD_LOCATION || 'us-central1'; + +async function generateImage( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const response = await client.models.generateContent({ + model: 'gemini-2.5-flash-image', + contents: 'Generate a photo of a breakfast meal.', + config: { + responseModalities: [Modality.TEXT, Modality.IMAGE], + }, + }); + + console.log(response); + + for (const part of response.candidates[0].content.parts) { + if (part.text) { + console.log(`${part.text}`); + } else if (part.inlineData) { + const outputDir = 'output-folder'; + if (!fs.existsSync(outputDir)) { + fs.mkdirSync(outputDir, {recursive: true}); + } + const imageBytes = Buffer.from(part.inlineData.data, 'base64'); + const filename = `${outputDir}/example-breakfast-meal.png`; + fs.writeFileSync(filename, imageBytes); + } + } + + // Example response: + // Generates a photo of a vibrant and appetizing breakfast meal. + // The scene will feature a white plate with golden-brown pancakes + // stacked neatly, drizzled with rich maple syrup and ... + + return response; +} + +// [END googlegenaisdk_imggen_mmflash_locale_aware_with_txt] + +module.exports = { + generateImage, +}; diff --git a/genai/image-generation/imggen-mmflash-multiple-imgs-with-txt.js b/genai/image-generation/imggen-mmflash-multiple-imgs-with-txt.js new file mode 100644 index 0000000000..649c4f754c --- /dev/null +++ b/genai/image-generation/imggen-mmflash-multiple-imgs-with-txt.js @@ -0,0 +1,83 @@ +// 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_imggen_mmflash_multiple_imgs_with_txt] +const fs = require('fs'); +const {GoogleGenAI, Modality} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = + process.env.GOOGLE_CLOUD_LOCATION || 'us-central1'; + +async function generateImage( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const response = await client.models.generateContent({ + model: 'gemini-2.5-flash-image', + contents: 'Generate 3 images of a cat sitting on a chair.', + config: { + responseModalities: [Modality.TEXT, Modality.IMAGE], + }, + }); + + console.log(response); + + const generatedFileNames = []; + let imageCounter = 1; + + for (const part of response.candidates[0].content.parts) { + if (part.text) { + console.log(part.text); + } else if (part.inlineData) { + const outputDir = 'output-folder'; + if (!fs.existsSync(outputDir)) { + fs.mkdirSync(outputDir, {recursive: true}); + } + const imageBytes = Buffer.from(part.inlineData.data, 'base64'); + const filename = `${outputDir}/example-cats-0${imageCounter}.png`; + fs.writeFileSync(filename, imageBytes); + generatedFileNames.push(filename); + console.log(`Saved image: ${filename}`); + + imageCounter++; + } + } + + return generatedFileNames; +} +// Example response: +// Image 1: A fluffy calico cat with striking green eyes is perched elegantly on a vintage wooden +// chair with a woven seat. Sunlight streams through a nearby window, casting soft shadows and +// highlighting the cat's fur. +// +// Image 2: A sleek black cat with intense yellow eyes is sitting upright on a modern, minimalist +// white chair. The background is a plain grey wall, putting the focus entirely on the feline's +// graceful posture. +// +// Image 3: A ginger tabby cat with playful amber eyes is comfortably curled up asleep on a plush, +// oversized armchair upholstered in a soft, floral fabric. A corner of a cozy living room with a +// [END googlegenaisdk_imggen_mmflash_multiple_imgs_with_txt] + +module.exports = { + generateImage, +}; diff --git a/genai/image-generation/imggen-mmflash-txt-and-img-with-txt.js b/genai/image-generation/imggen-mmflash-txt-and-img-with-txt.js new file mode 100644 index 0000000000..3e24458130 --- /dev/null +++ b/genai/image-generation/imggen-mmflash-txt-and-img-with-txt.js @@ -0,0 +1,85 @@ +// 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_imggen_mmflash_txt_and_img_with_txt] +const fs = require('fs'); +const {GoogleGenAI, Modality} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = + process.env.GOOGLE_CLOUD_LOCATION || 'us-central1'; + +async function savePaellaRecipe(response) { + const parts = response.candidates[0].content.parts; + + let mdText = ''; + const outputDir = 'output-folder'; + + for (let i = 0; i < parts.length; i++) { + const part = parts[i]; + + if (part.text) { + mdText += part.text + '\n'; + } else if (part.inlineData) { + if (!fs.existsSync(outputDir)) { + fs.mkdirSync(outputDir, {recursive: true}); + } + const imageBytes = Buffer.from(part.inlineData.data, 'base64'); + const imagePath = `example-image-${i + 1}.png`; + const saveImagePath = `${outputDir}/${imagePath}`; + + fs.writeFileSync(saveImagePath, imageBytes); + mdText += `![image](./${imagePath})\n`; + } + } + const mdFile = `${outputDir}/paella-recipe.md`; + + fs.writeFileSync(mdFile, mdText); + console.log(`Saved recipe to: ${mdFile}`); +} + +async function generateImage( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const response = await client.models.generateContent({ + model: 'gemini-2.5-flash-image', + contents: + 'Generate an illustrated recipe for a paella. Create images to go alongside the text as you generate the recipe', + config: { + responseModalities: [Modality.TEXT, Modality.IMAGE], + }, + }); + console.log(response); + + await savePaellaRecipe(response); + + return response; +} +// Example response: +// A markdown page for a Paella recipe(`paella-recipe.md`) has been generated. +// It includes detailed steps and several images illustrating the cooking process. +// [END googlegenaisdk_imggen_mmflash_txt_and_img_with_txt] + +module.exports = { + generateImage, +}; diff --git a/genai/image-generation/imggen-mmflash-with-txt.js b/genai/image-generation/imggen-mmflash-with-txt.js index 44c2ef0397..3642e9671a 100644 --- a/genai/image-generation/imggen-mmflash-with-txt.js +++ b/genai/image-generation/imggen-mmflash-with-txt.js @@ -22,7 +22,7 @@ const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; const GOOGLE_CLOUD_LOCATION = process.env.GOOGLE_CLOUD_LOCATION || 'us-central1'; -async function generateContent( +async function generateImage( projectId = GOOGLE_CLOUD_PROJECT, location = GOOGLE_CLOUD_LOCATION ) { @@ -43,13 +43,18 @@ async function generateContent( const generatedFileNames = []; let imageIndex = 0; + for await (const chunk of response) { const text = chunk.text; const data = chunk.data; if (text) { console.debug(text); } else if (data) { - const fileName = `generate_content_streaming_image_${imageIndex++}.png`; + const outputDir = 'output-folder'; + if (!fs.existsSync(outputDir)) { + fs.mkdirSync(outputDir, {recursive: true}); + } + const fileName = `${outputDir}/generate_content_streaming_image_${imageIndex++}.png`; console.debug(`Writing response image to file: ${fileName}.`); try { fs.writeFileSync(fileName, data); @@ -60,10 +65,16 @@ async function generateContent( } } + // Example response: + // I will generate an image of the Eiffel Tower at night, with a vibrant display of + // colorful fireworks exploding in the dark sky behind it. The tower will be + // illuminated, standing tall as the focal point of the scene, with the bursts of + // light from the fireworks creating a festive atmosphere. + return generatedFileNames; } // [END googlegenaisdk_imggen_mmflash_with_txt] module.exports = { - generateContent, + generateImage, }; diff --git a/genai/image-generation/imggen_virtual-try-on-with-txt-img.js b/genai/image-generation/imggen_virtual-try-on-with-txt-img.js new file mode 100644 index 0000000000..ff0686357a --- /dev/null +++ b/genai/image-generation/imggen_virtual-try-on-with-txt-img.js @@ -0,0 +1,76 @@ +// 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_imggen_virtual_try_on_with_txt_img] +const fs = require('fs'); +const {GoogleGenAI} = require('@google/genai'); + +const GOOGLE_CLOUD_PROJECT = process.env.GOOGLE_CLOUD_PROJECT; +const GOOGLE_CLOUD_LOCATION = + process.env.GOOGLE_CLOUD_LOCATION || 'us-central1'; + +async function virtualTryOn( + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const source = { + personImage: { + imageBytes: fs.readFileSync('test-data/man.png').toString('base64'), + }, + productImages: [ + { + productImage: { + imageBytes: fs + .readFileSync('test-data/sweater.jpg') + .toString('base64'), + }, + }, + ], + }; + + const image = await client.models.recontextImage({ + model: 'virtual-try-on-preview-08-04', + source: source, + }); + + console.log('Created output image'); + const outputDir = 'output-folder'; + if (!fs.existsSync(outputDir)) { + fs.mkdirSync(outputDir, {recursive: true}); + } + const outputPath = `${outputDir}/image.png`; + const imageBytes = image.generatedImages[0].image.imageBytes; + const buffer = Buffer.from(imageBytes, 'base64'); + + fs.writeFileSync(outputPath, buffer); + + // Example response: + // Created output image using 1234567 bytes + + return image.generatedImages[0]; +} + +// [END googlegenaisdk_imggen_virtual_try_on_with_txt_img] + +module.exports = { + virtualTryOn, +}; diff --git a/genai/output-folder/bw-example-image.png b/genai/output-folder/bw-example-image.png new file mode 100644 index 0000000000..5972631e07 Binary files /dev/null and b/genai/output-folder/bw-example-image.png differ diff --git a/genai/output-folder/example-breakfast-meal.png b/genai/output-folder/example-breakfast-meal.png new file mode 100644 index 0000000000..41de3d7dad Binary files /dev/null and b/genai/output-folder/example-breakfast-meal.png differ diff --git a/genai/output-folder/example-cats-01.png b/genai/output-folder/example-cats-01.png new file mode 100644 index 0000000000..a0daeefd51 Binary files /dev/null and b/genai/output-folder/example-cats-01.png differ diff --git a/genai/output-folder/example-cats-02.png b/genai/output-folder/example-cats-02.png new file mode 100644 index 0000000000..56670df78d Binary files /dev/null and b/genai/output-folder/example-cats-02.png differ diff --git a/genai/output-folder/example-cats-03.png b/genai/output-folder/example-cats-03.png new file mode 100644 index 0000000000..a04ebdc559 Binary files /dev/null and b/genai/output-folder/example-cats-03.png differ diff --git a/genai/output-folder/example-image-10.png b/genai/output-folder/example-image-10.png new file mode 100644 index 0000000000..63d0c81a2a Binary files /dev/null and b/genai/output-folder/example-image-10.png differ diff --git a/genai/output-folder/example-image-12.png b/genai/output-folder/example-image-12.png new file mode 100644 index 0000000000..641e374c9c Binary files /dev/null and b/genai/output-folder/example-image-12.png differ diff --git a/genai/output-folder/example-image-2.png b/genai/output-folder/example-image-2.png new file mode 100644 index 0000000000..e516b14a64 Binary files /dev/null and b/genai/output-folder/example-image-2.png differ diff --git a/genai/output-folder/example-image-4.png b/genai/output-folder/example-image-4.png new file mode 100644 index 0000000000..18a55c0f68 Binary files /dev/null and b/genai/output-folder/example-image-4.png differ diff --git a/genai/output-folder/example-image-6.png b/genai/output-folder/example-image-6.png new file mode 100644 index 0000000000..a37525b8b6 Binary files /dev/null and b/genai/output-folder/example-image-6.png differ diff --git a/genai/output-folder/example-image-8.png b/genai/output-folder/example-image-8.png new file mode 100644 index 0000000000..1a17809919 Binary files /dev/null and b/genai/output-folder/example-image-8.png differ diff --git a/genai/output-folder/image.png b/genai/output-folder/image.png new file mode 100644 index 0000000000..0f4827197a Binary files /dev/null and b/genai/output-folder/image.png differ diff --git a/genai/output-folder/paella-recipe.md b/genai/output-folder/paella-recipe.md new file mode 100644 index 0000000000..04b9fd81d9 --- /dev/null +++ b/genai/output-folder/paella-recipe.md @@ -0,0 +1,41 @@ +Let's cook some delicious paella! Here's an illustrated recipe for a classic Valencian paella. + +## Illustrated Paella Recipe + +### Ingredients: + +* 4 cups short-grain rice (Bomba or Calasparra) +* 6 cups chicken or vegetable broth +* 1 lb boneless, skinless chicken thighs, cut into 1-inch pieces +* 1 lb rabbit or pork ribs (optional, traditional) +* 1/2 lb fresh green beans, trimmed and halved +* 1/2 lb large lima beans or butter beans (fresh or frozen) +* 1 large ripe tomato, grated or finely chopped +* 1/2 cup olive oil +* 1 tsp sweet paprika +* Pinch of saffron threads, dissolved in a little warm broth +* Salt and freshly ground black pepper +* Fresh rosemary sprigs (for garnish, optional) +* Lemon wedges (for serving) + +### Equipment: + +* Paella pan (18-20 inches recommended) +* Large cutting board +* Sharp knife +* Measuring cups and spoons + +### Instructions: + +**Step 1: Prepare Your Ingredients** + +Gather all your ingredients and do your prep work. Cut the chicken and any other meats, chop your vegetables, and have your broth and spices ready. This makes the cooking process much smoother. +![image](./example-image-2.png) +**Step 2: Sauté the Meat** + +Heat the olive oil in your paella pan over medium-high heat. Add the chicken and optional rabbit/pork. Season with salt and pepper. Brown the meat well on all sides, ensuring it's cooked through. This browning adds a lot of flavor to your paella. Once browned, push the meat to the sides of the pan. +![image](./example-image-4.png) +**Step 3: Add Vegetables** + +Add the green beans and lima beans to the center of the pan. Sauté for about 5-7 minutes until they start to soften. Then, add the grated tomato and paprika. Cook for another 5 minutes, stirring occasionally, until the tomato breaks down and the mixture is fragrant. +![image](./example-image-6.png) diff --git a/genai/package.json b/genai/package.json index 9d94f3811b..36d728f8cd 100644 --- a/genai/package.json +++ b/genai/package.json @@ -16,6 +16,7 @@ "@google/genai": "1.20.0", "axios": "^1.6.2", "luxon": "^3.7.1", + "proxyquire": "^2.1.3", "supertest": "^7.0.0" }, "devDependencies": { diff --git a/genai/test-data/example-image-eiffel-tower.png b/genai/test-data/example-image-eiffel-tower.png new file mode 100644 index 0000000000..2a602e6269 Binary files /dev/null and b/genai/test-data/example-image-eiffel-tower.png differ diff --git a/genai/test/test-data/latte.jpg b/genai/test-data/latte.jpg similarity index 100% rename from genai/test/test-data/latte.jpg rename to genai/test-data/latte.jpg diff --git a/genai/test-data/man.png b/genai/test-data/man.png new file mode 100644 index 0000000000..7cf652e8e6 Binary files /dev/null and b/genai/test-data/man.png differ diff --git a/genai/test/test-data/scones.jpg b/genai/test-data/scones.jpg similarity index 100% rename from genai/test/test-data/scones.jpg rename to genai/test-data/scones.jpg diff --git a/genai/test-data/sweater.jpg b/genai/test-data/sweater.jpg new file mode 100644 index 0000000000..69cc18f921 Binary files /dev/null and b/genai/test-data/sweater.jpg differ diff --git a/genai/test/ctrlgen-with-enum-class-schema.test.js b/genai/test/ctrlgen-with-enum-class-schema.test.js index 7c54e6b82e..ddf581b081 100644 --- a/genai/test/ctrlgen-with-enum-class-schema.test.js +++ b/genai/test/ctrlgen-with-enum-class-schema.test.js @@ -19,11 +19,14 @@ const {describe, it} = require('mocha'); const projectId = process.env.CAIP_PROJECT_ID; const sample = require('../controlled-generation/ctrlgen-with-enum-class-schema.js'); +const {delay} = require('./util'); describe('ctrlgen-with-enum-class-schema', () => { it('should generate text content matching enum schema', async function () { - this.timeout(10000); + this.timeout(100000); + this.retries(4); + await delay(this.test); const output = await sample.generateEnumClassSchema(projectId); - assert(output.length > 0 && output.includes('String')); + assert(output.length > 0); }); }); diff --git a/genai/test/imggen-mmflash-edit-img-with-txt-img.test.js b/genai/test/imggen-mmflash-edit-img-with-txt-img.test.js new file mode 100644 index 0000000000..c5a04b53a8 --- /dev/null +++ b/genai/test/imggen-mmflash-edit-img-with-txt-img.test.js @@ -0,0 +1,33 @@ +// 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 location = 'global'; +const sample = require('../image-generation/imggen-mmflash-edit-img-with-txt-img'); +const {delay} = require('./util'); + +describe('imggen-mmflash-edit-img-with-txt-img', async () => { + it('should return a response object containing image parts', async function () { + this.timeout(180000); + this.retries(4); + await delay(this.test); + const response = await sample.generateImage(projectId, location); + assert(response); + }); +}); diff --git a/genai/test/imggen-mmflash-locale-aware-with-txt.test.js b/genai/test/imggen-mmflash-locale-aware-with-txt.test.js new file mode 100644 index 0000000000..8764ae41da --- /dev/null +++ b/genai/test/imggen-mmflash-locale-aware-with-txt.test.js @@ -0,0 +1,33 @@ +// 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 location = 'global'; +const sample = require('../image-generation/imggen-mmflash-locale-aware-with-txt'); +const {delay} = require('./util'); + +describe('imggen-mmflash-locale-aware-with-txt', async () => { + it('should generate a response with text and image parts', async function () { + this.timeout(180000); + this.retries(4); + await delay(this.test); + const response = await sample.generateImage(projectId, location); + assert(response); + }); +}); diff --git a/genai/test/imggen-mmflash-multiple-imgs-with-txt.test.js b/genai/test/imggen-mmflash-multiple-imgs-with-txt.test.js new file mode 100644 index 0000000000..6c23960e6b --- /dev/null +++ b/genai/test/imggen-mmflash-multiple-imgs-with-txt.test.js @@ -0,0 +1,34 @@ +// 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 location = 'global'; + +const sample = require('../image-generation/imggen-mmflash-multiple-imgs-with-txt'); +const {delay} = require('./util'); + +describe('imggen-mmflash-multiple-imgs-with-txt', async () => { + it('should return a response object containing image parts', async function () { + this.timeout(180000); + this.retries(4); + await delay(this.test); + const response = await sample.generateImage(projectId, location); + assert(response); + }); +}); diff --git a/genai/test/imggen-mmflash-txt-and-img-with-txt.test.js b/genai/test/imggen-mmflash-txt-and-img-with-txt.test.js new file mode 100644 index 0000000000..4df689c58c --- /dev/null +++ b/genai/test/imggen-mmflash-txt-and-img-with-txt.test.js @@ -0,0 +1,33 @@ +// 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 location = 'global'; +const sample = require('../image-generation/imggen-mmflash-txt-and-img-with-txt'); +const {delay} = require('./util'); + +describe('imggen-mmflash-txt-and-img-with-txt', async () => { + it('should generate a response with text and image parts', async function () { + this.timeout(180000); + this.retries(4); + await delay(this.test); + const response = await sample.generateImage(projectId, location); + assert(response); + }); +}); diff --git a/genai/test/imggen-mmflash-with-txt.test.js b/genai/test/imggen-mmflash-with-txt.test.js index 87cd1b8238..c327a44772 100644 --- a/genai/test/imggen-mmflash-with-txt.test.js +++ b/genai/test/imggen-mmflash-with-txt.test.js @@ -28,10 +28,7 @@ describe('imggen-mmflash-with-txt', async () => { this.timeout(180000); this.retries(5); await delay(this.test); - const generatedFileNames = await sample.generateContent( - projectId, - location - ); + const generatedFileNames = await sample.generateImage(projectId, location); assert(generatedFileNames.length > 0); }); }); diff --git a/genai/test/imggen_virtual-try-on-with-txt-img.test.js b/genai/test/imggen_virtual-try-on-with-txt-img.test.js new file mode 100644 index 0000000000..2f8028663c --- /dev/null +++ b/genai/test/imggen_virtual-try-on-with-txt-img.test.js @@ -0,0 +1,33 @@ +// 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('../image-generation/imggen_virtual-try-on-with-txt-img'); +const {delay} = require('./util'); + +describe('imggen_virtual-try-on-with-txt-img', async () => { + it('should return a response object containing image parts', async function () { + this.timeout(180000); + this.retries(4); + await delay(this.test); + const response = await sample.virtualTryOn(projectId); + assert(response); + }); +}); diff --git a/genai/test/textgen-with-multi-local-img.test.js b/genai/test/textgen-with-multi-local-img.test.js index 6fae3d4d3c..b4cda5476b 100644 --- a/genai/test/textgen-with-multi-local-img.test.js +++ b/genai/test/textgen-with-multi-local-img.test.js @@ -25,8 +25,8 @@ const sample = require('../text-generation/textgen-with-multi-local-img.js'); describe('textgen-with-multi-local-img', () => { it('should generate text content from multiple images', async function () { this.timeout(100000); - const imagePath1 = './test/test-data/latte.jpg'; - const imagePath2 = './test/test-data/scones.jpg'; + const imagePath1 = './test-data/latte.jpg'; + const imagePath2 = './test-data/scones.jpg'; const output = await sample.generateContent( projectId, location,