From fe00be5eb421e7162b477dbf381f93817234ee58 Mon Sep 17 00:00:00 2001 From: Guiners Date: Thu, 30 Oct 2025 16:08:36 +0100 Subject: [PATCH 1/9] adding imggen samples --- .../imggen-canny-ctrl-type-with-txt-img.js | 69 +++++++++++++++ .../imggen-raw-reference-with-txt-img.js | 69 +++++++++++++++ .../imggen-scribble-ctrl-type-with-txt-img.js | 69 +++++++++++++++ .../imggen-style-reference-with-txt-img.js | 73 ++++++++++++++++ ...gen-subj-refer-ctrl-refer-with-txt-imgs.js | 86 +++++++++++++++++++ genai/image-generation/imggen-with-txt.js | 63 ++++++++++++++ ...mggen-canny-ctrl-type-with-txt-img.test.js | 38 ++++++++ .../imggen-raw-reference-with-txt-img.test.js | 38 ++++++++ ...en-scribble-ctrl-type-with-txt-img.test.js | 38 ++++++++ ...mggen-style-reference-with-txt-img.test.js | 38 ++++++++ ...ubj-refer-ctrl-refer-with-txt-imgs.test.js | 38 ++++++++ genai/test/imggen-util.js | 26 ++++++ genai/test/imggen-with-txt.test.js | 32 +++++++ 13 files changed, 677 insertions(+) create mode 100644 genai/image-generation/imggen-canny-ctrl-type-with-txt-img.js create mode 100644 genai/image-generation/imggen-raw-reference-with-txt-img.js create mode 100644 genai/image-generation/imggen-scribble-ctrl-type-with-txt-img.js create mode 100644 genai/image-generation/imggen-style-reference-with-txt-img.js create mode 100644 genai/image-generation/imggen-subj-refer-ctrl-refer-with-txt-imgs.js create mode 100644 genai/image-generation/imggen-with-txt.js create mode 100644 genai/test/imggen-canny-ctrl-type-with-txt-img.test.js create mode 100644 genai/test/imggen-raw-reference-with-txt-img.test.js create mode 100644 genai/test/imggen-scribble-ctrl-type-with-txt-img.test.js create mode 100644 genai/test/imggen-style-reference-with-txt-img.test.js create mode 100644 genai/test/imggen-subj-refer-ctrl-refer-with-txt-imgs.test.js create mode 100644 genai/test/imggen-util.js create mode 100644 genai/test/imggen-with-txt.test.js diff --git a/genai/image-generation/imggen-canny-ctrl-type-with-txt-img.js b/genai/image-generation/imggen-canny-ctrl-type-with-txt-img.js new file mode 100644 index 0000000000..d9d2775aab --- /dev/null +++ b/genai/image-generation/imggen-canny-ctrl-type-with-txt-img.js @@ -0,0 +1,69 @@ +// 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_canny_ctrl_type_with_txt_img] +const {GoogleGenAI, ControlReferenceImage} = 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( + outputGcsUri, + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const controlReferenceImage = new ControlReferenceImage(); + controlReferenceImage.referenceId = 1; + controlReferenceImage.referenceImage = { + gcsUri: 'gs://cloud-samples-data/generative-ai/image/car_canny.png', + }; + controlReferenceImage.config = { + controlType: 'CONTROL_TYPE_CANNY', + }; + + // TODO(developer): Update and un-comment below line + // outputGcsUri = "gs://your-bucket/your-prefix" + + const response = await client.models.editImage({ + model: 'imagen-3.0-capability-001', + prompt: 'a watercolor painting of a red car[1] driving on a road', + referenceImages: [controlReferenceImage], + config: { + editMode: 'EDIT_MODE_CONTROLLED_EDITING', + numberOfImages: 1, + safetyFilterLevel: 'BLOCK_MEDIUM_AND_ABOVE', + personGeneration: 'ALLOW_ADULT', + outputGcsUri: outputGcsUri, + }, + }); + console.log(response.generatedImages); + + // Example response: + // gs://your-bucket/your-prefix + return response.generatedImages; +} +// [END googlegenaisdk_imggen_canny_ctrl_type_with_txt_img] + +module.exports = { + generateImage, +}; diff --git a/genai/image-generation/imggen-raw-reference-with-txt-img.js b/genai/image-generation/imggen-raw-reference-with-txt-img.js new file mode 100644 index 0000000000..9e7ca07ef4 --- /dev/null +++ b/genai/image-generation/imggen-raw-reference-with-txt-img.js @@ -0,0 +1,69 @@ +// 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. + +// [START googlegenaisdk_imggen_raw_reference_with_txt_img] + +'use strict'; + +const {GoogleGenAI, RawReferenceImage} = 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( + outputGcsUri, + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const client = new GoogleGenAI({ + project: projectId, + location: location, + }); + + const referenceImages = new RawReferenceImage(); + referenceImages.referenceId = 1; + referenceImages.referenceImage = { + gcsUri: 'gs://cloud-samples-data/generative-ai/image/teacup-1.png', + }; + + // TODO(developer): Update and un-comment below line + // outputGcsUri = "gs://your-bucket/your-prefix" + + const response = await client.models.editImage({ + model: 'imagen-3.0-capability-001', + prompt: + 'transform the subject in the image so that the teacup[1] is made entirely out of chocolate', + referenceImages: [referenceImages], + config: { + editMode: 'EDIT_MODE_DEFAULT', + numberOfImages: 1, + safetyFilterLevel: 'BLOCK_MEDIUM_AND_ABOVE', + personGeneration: 'ALLOW_ADULT', + outputGcsUri: outputGcsUri, + }, + }); + + console.log(response); + + // Example response: + // gs://your-bucket/your-prefix + + return response.generatedImages[0].image.gcsUri; +} +// [END googlegenaisdk_imggen_raw_reference_with_txt_img] + +module.exports = { + generateImage, +}; diff --git a/genai/image-generation/imggen-scribble-ctrl-type-with-txt-img.js b/genai/image-generation/imggen-scribble-ctrl-type-with-txt-img.js new file mode 100644 index 0000000000..0b42934f9c --- /dev/null +++ b/genai/image-generation/imggen-scribble-ctrl-type-with-txt-img.js @@ -0,0 +1,69 @@ +// 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_scribble_ctrl_type_with_txt_img] +const {GoogleGenAI, ControlReferenceImage} = 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( + outputGcsUri, + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const controlReferenceImage = new ControlReferenceImage(); + controlReferenceImage.referenceId = 1; + controlReferenceImage.referenceImage = { + gcsUri: 'gs://cloud-samples-data/generative-ai/image/car_scribble.png', + }; + controlReferenceImage.config = { + controlType: 'CONTROL_TYPE_SCRIBBLE', + }; + + // TODO(developer): Update and un-comment below line + // outputGcsUri = "gs://your-bucket/your-prefix" + + const response = await client.models.editImage({ + model: 'imagen-3.0-capability-001', + prompt: 'an oil painting showing the side of a red car[1]', + referenceImages: [controlReferenceImage], + config: { + editMode: 'EDIT_MODE_CONTROLLED_EDITING', + numberOfImages: 1, + safetyFilterLevel: 'BLOCK_MEDIUM_AND_ABOVE', + personGeneration: 'ALLOW_ADULT', + outputGcsUri: outputGcsUri, + }, + }); + console.log(response.generatedImages); + + // Example response: + // gs://your-bucket/your-prefix + return response.generatedImages; +} +// [END googlegenaisdk_imggen_scribble_ctrl_type_with_txt_img] + +module.exports = { + generateImage, +}; diff --git a/genai/image-generation/imggen-style-reference-with-txt-img.js b/genai/image-generation/imggen-style-reference-with-txt-img.js new file mode 100644 index 0000000000..163687278e --- /dev/null +++ b/genai/image-generation/imggen-style-reference-with-txt-img.js @@ -0,0 +1,73 @@ +// 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_style_reference_with_txt_img] +const {GoogleGenAI, StyleReferenceImage} = 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( + outputGcsUri, + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + // Create a style reference image of a neon sign stored in Google Cloud Storage + // using https://storage.googleapis.com/cloud-samples-data/generative-ai/image/neon.png + + // TODO(developer): Update and un-comment below line + // outputGcsUri = "gs://your-bucket/your-prefix" + + const styleReferenceImage = new StyleReferenceImage(); + styleReferenceImage.referenceId = 1; + styleReferenceImage.referenceImage = { + gcsUri: 'gs://cloud-samples-data/generative-ai/image/neon.png', + }; + styleReferenceImage.config = { + styleDescription: 'neon sign', + }; + + const response = await client.models.editImage({ + model: 'imagen-3.0-capability-001', + prompt: + 'generate an image of a neon sign [1] with the words: have a great day', + referenceImages: [styleReferenceImage], + config: { + editMode: 'EDIT_MODE_CONTROLLED_EDITING', + numberOfImages: 1, + safetyFilterLevel: 'BLOCK_MEDIUM_AND_ABOVE', + personGeneration: 'ALLOW_ADULT', + outputGcsUri: outputGcsUri, + }, + }); + console.log(response.generatedImages); + + // Example response: + // gs://your-bucket/your-prefix + return response.generatedImages; +} +// [END googlegenaisdk_imggen_style_reference_with_txt_img] + +module.exports = { + generateImage, +}; diff --git a/genai/image-generation/imggen-subj-refer-ctrl-refer-with-txt-imgs.js b/genai/image-generation/imggen-subj-refer-ctrl-refer-with-txt-imgs.js new file mode 100644 index 0000000000..139a20ad73 --- /dev/null +++ b/genai/image-generation/imggen-subj-refer-ctrl-refer-with-txt-imgs.js @@ -0,0 +1,86 @@ +// 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_subj_refer_ctrl_refer_with_txt_imgs] +const { + GoogleGenAI, + ControlReferenceImage, + SubjectReferenceImage, +} = 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( + outputGcsUri, + projectId = GOOGLE_CLOUD_PROJECT, + location = GOOGLE_CLOUD_LOCATION +) { + const client = new GoogleGenAI({ + vertexai: true, + project: projectId, + location: location, + }); + + const subjectReferenceImage = new SubjectReferenceImage(); + subjectReferenceImage.referenceId = 1; + subjectReferenceImage.referenceImage = { + gcsUri: 'gs://cloud-samples-data/generative-ai/image/person.png', + }; + subjectReferenceImage.config = { + subjectDescription: 'a headshot of a woman', + subjectType: 'SUBJECT_TYPE_PERSON', + }; + + const controlReferenceImage = new ControlReferenceImage(); + controlReferenceImage.referenceId = 2; + controlReferenceImage.referenceImage = { + gcsUri: 'gs://cloud-samples-data/generative-ai/image/person.png', + }; + controlReferenceImage.config = { + controlType: 'CONTROL_TYPE_FACE_MESH', + }; + + // TODO(developer): Update and un-comment below line + // outputGcsUri = "gs://your-bucket/your-prefix" + + const response = await client.models.editImage({ + model: 'imagen-3.0-capability-001', + prompt: + 'a portrait of a woman[1] in the pose of the control image[2]in a watercolor style by a professional artist,\n' + + ' light and low-contrast stokes, bright pastel colors, a warm atmosphere, clean background, grainy paper,\n' + + ' bold visible brushstrokes, patchy details', + referenceImages: [subjectReferenceImage, controlReferenceImage], + config: { + editMode: 'EDIT_MODE_CONTROLLED_EDITING', + numberOfImages: 1, + safetyFilterLevel: 'BLOCK_MEDIUM_AND_ABOVE', + personGeneration: 'ALLOW_ADULT', + outputGcsUri: outputGcsUri, + }, + }); + console.log(response.generatedImages); + + // Example response: + // gs://your-bucket/your-prefix + return response.generatedImages; +} +// [END googlegenaisdk_imggen_subj_refer_ctrl_refer_with_txt_imgs] + +module.exports = { + generateImage, +}; diff --git a/genai/image-generation/imggen-with-txt.js b/genai/image-generation/imggen-with-txt.js new file mode 100644 index 0000000000..003c7563b9 --- /dev/null +++ b/genai/image-generation/imggen-with-txt.js @@ -0,0 +1,63 @@ +// 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_with_txt] +const {GoogleGenAI} = require('@google/genai'); +const fs = require('fs'); + +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 image = await client.models.generateImages({ + model: 'imagen-4.0-generate-001', + prompt: 'A dog reading a newspaper', + config: { + imageSize: '2K', + }, + }); + console.log(image.generatedImages[0].image); + console.log('Created output image'); + const outputDir = 'output-folder'; + if (!fs.existsSync(outputDir)) { + fs.mkdirSync(outputDir, {recursive: true}); + } + + const imageBytes = image.generatedImages[0].image.imageBytes; + const buffer = Buffer.from(imageBytes, 'base64'); + const fileName = `${outputDir}/dog-image.png`; + + fs.writeFileSync(fileName, buffer); + + // Example response: + // gs://your-bucket/your-prefix + return image.generatedImages; +} +// [END googlegenaisdk_imggen_with_txt] + +module.exports = { + generateImage, +}; diff --git a/genai/test/imggen-canny-ctrl-type-with-txt-img.test.js b/genai/test/imggen-canny-ctrl-type-with-txt-img.test.js new file mode 100644 index 0000000000..e059c90a7e --- /dev/null +++ b/genai/test/imggen-canny-ctrl-type-with-txt-img.test.js @@ -0,0 +1,38 @@ +// 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-canny-ctrl-type-with-txt-img'); +const {delay} = require('./util'); +const {createOutputGcsUri} = require('./imggen-util'); +describe('imggen-canny-ctrl-type-with-txt-img', () => { + it('should return an array of generated image URIs', async function () { + this.timeout(180000); + this.retries(4); + const output = await createOutputGcsUri(); + console.log(output.uri); + await delay(this.test); + const generatedFileNames = await sample.generateImage( + output.uri, + projectId + ); + assert(generatedFileNames.length > 0); + }); +}); diff --git a/genai/test/imggen-raw-reference-with-txt-img.test.js b/genai/test/imggen-raw-reference-with-txt-img.test.js new file mode 100644 index 0000000000..1ff747850d --- /dev/null +++ b/genai/test/imggen-raw-reference-with-txt-img.test.js @@ -0,0 +1,38 @@ +// 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-raw-reference-with-txt-img'); +const {delay} = require('./util'); +const {createOutputGcsUri} = require('./imggen-util'); +describe('imggen-raw-reference-with-txt-img', () => { + it('should return a GCS URI string', async function () { + this.timeout(180000); + this.retries(4); + const output = await createOutputGcsUri(); + console.log(output.uri); + await delay(this.test); + const generatedFileNames = await sample.generateImage( + output.uri, + projectId + ); + assert(generatedFileNames.length > 0); + }); +}); diff --git a/genai/test/imggen-scribble-ctrl-type-with-txt-img.test.js b/genai/test/imggen-scribble-ctrl-type-with-txt-img.test.js new file mode 100644 index 0000000000..f8415225d1 --- /dev/null +++ b/genai/test/imggen-scribble-ctrl-type-with-txt-img.test.js @@ -0,0 +1,38 @@ +// 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-scribble-ctrl-type-with-txt-img'); +const {delay} = require('./util'); +const {createOutputGcsUri} = require('./imggen-util'); + +describe('imggen-scribble-ctrl-type-with-txt-img', async () => { + it('should generate images from a text prompt with control reference image', async function () { + this.timeout(180000); + this.retries(4); + const output = await createOutputGcsUri(); + console.log(output.uri); + await delay(this.test); + const generatedFileNames = await sample.generateImage( + output.uri, + projectId + ); + assert(generatedFileNames.length > 0); + }); +}); diff --git a/genai/test/imggen-style-reference-with-txt-img.test.js b/genai/test/imggen-style-reference-with-txt-img.test.js new file mode 100644 index 0000000000..0e96371d0e --- /dev/null +++ b/genai/test/imggen-style-reference-with-txt-img.test.js @@ -0,0 +1,38 @@ +// 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-style-reference-with-txt-img'); +const {delay} = require('./util'); +const {createOutputGcsUri} = require('./imggen-util'); + +describe('imggen-style-reference-with-txt-img', async () => { + it('should generate images from a text prompt with style reference', async function () { + this.timeout(180000); + this.retries(4); + const output = await createOutputGcsUri(); + console.log(output.uri); + await delay(this.test); + const generatedFileNames = await sample.generateImage( + output.uri, + projectId + ); + assert(generatedFileNames.length > 0); + }); +}); diff --git a/genai/test/imggen-subj-refer-ctrl-refer-with-txt-imgs.test.js b/genai/test/imggen-subj-refer-ctrl-refer-with-txt-imgs.test.js new file mode 100644 index 0000000000..969a24127a --- /dev/null +++ b/genai/test/imggen-subj-refer-ctrl-refer-with-txt-imgs.test.js @@ -0,0 +1,38 @@ +// 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-subj-refer-ctrl-refer-with-txt-imgs'); +const {delay} = require('./util'); +const {createOutputGcsUri} = require('./imggen-util'); + +describe('imggen-subj-refer-ctrl-refer-with-txt-imgs', async () => { + it('should generate images from a text prompt with subject reference image and control reference image', async function () { + this.timeout(180000); + this.retries(4); + const output = await createOutputGcsUri(); + console.log(output.uri); + await delay(this.test); + const generatedFileNames = await sample.generateImage( + output.uri, + projectId + ); + assert(generatedFileNames.length > 0); + }); +}); diff --git a/genai/test/imggen-util.js b/genai/test/imggen-util.js new file mode 100644 index 0000000000..38ba78092b --- /dev/null +++ b/genai/test/imggen-util.js @@ -0,0 +1,26 @@ +const {Storage} = require('@google-cloud/storage'); +const {format} = require('date-fns'); + +// local +const gcsOutputBucket = + 'example-cloud-bucket-5439474/nodejs-docs-samples-tests'; + +//uncomment +// const gcsOutputBucket = "nodejs-docs-samples-tests"; + +module.exports.createOutputGcsUri = async function () { + const prefix = `text_output/${format(new Date(), 'yyyy-MM-dd-HH-mm-ss')}`; + const gcsUri = `gs://${gcsOutputBucket}/${prefix}`; + + return { + uri: gcsUri, + async cleanup() { + const storage = new Storage(); + const bucket = storage.bucket(gcsOutputBucket); + + const [files] = await bucket.getFiles({prefix}); + await Promise.all(files.map(file => file.delete())); + console.log(`Deleted ${files.length} files from ${prefix}`); + }, + }; +}; diff --git a/genai/test/imggen-with-txt.test.js b/genai/test/imggen-with-txt.test.js new file mode 100644 index 0000000000..2737143851 --- /dev/null +++ b/genai/test/imggen-with-txt.test.js @@ -0,0 +1,32 @@ +// 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-with-txt.js'); +const {delay} = require('./util'); + +describe('imggen-with-txt', async () => { + it('should generate images from a text prompt', async function () { + this.timeout(180000); + this.retries(4); + await delay(this.test); + const image = await sample.generateImage(projectId); + assert(image.length > 0); + }); +}); From 728ad9287a82e2cc63e700a051d7c8df6d64302a Mon Sep 17 00:00:00 2001 From: Guiners Date: Thu, 6 Nov 2025 10:20:58 +0100 Subject: [PATCH 2/9] adding license --- genai/test/imggen-util.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/genai/test/imggen-util.js b/genai/test/imggen-util.js index 38ba78092b..d59b1f3a12 100644 --- a/genai/test/imggen-util.js +++ b/genai/test/imggen-util.js @@ -1,3 +1,17 @@ +// 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. + const {Storage} = require('@google-cloud/storage'); const {format} = require('date-fns'); From 1381b086acfa5d179915cef58636502d60777136 Mon Sep 17 00:00:00 2001 From: Robert Kozak <50328216+Guiners@users.noreply.github.com> Date: Fri, 7 Nov 2025 10:41:30 +0100 Subject: [PATCH 3/9] Update genai/image-generation/imggen-subj-refer-ctrl-refer-with-txt-imgs.js Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- .../imggen-subj-refer-ctrl-refer-with-txt-imgs.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/genai/image-generation/imggen-subj-refer-ctrl-refer-with-txt-imgs.js b/genai/image-generation/imggen-subj-refer-ctrl-refer-with-txt-imgs.js index 139a20ad73..19946ec8fd 100644 --- a/genai/image-generation/imggen-subj-refer-ctrl-refer-with-txt-imgs.js +++ b/genai/image-generation/imggen-subj-refer-ctrl-refer-with-txt-imgs.js @@ -61,9 +61,9 @@ async function generateImage( const response = await client.models.editImage({ model: 'imagen-3.0-capability-001', prompt: - 'a portrait of a woman[1] in the pose of the control image[2]in a watercolor style by a professional artist,\n' + - ' light and low-contrast stokes, bright pastel colors, a warm atmosphere, clean background, grainy paper,\n' + - ' bold visible brushstrokes, patchy details', + `a portrait of a woman[1] in the pose of the control image[2]in a watercolor style by a professional artist, + light and low-contrast stokes, bright pastel colors, a warm atmosphere, clean background, grainy paper, + bold visible brushstrokes, patchy details`, referenceImages: [subjectReferenceImage, controlReferenceImage], config: { editMode: 'EDIT_MODE_CONTROLLED_EDITING', From 4ee6e73aa570e138017dddbc6fa424493fff577e Mon Sep 17 00:00:00 2001 From: Robert Kozak <50328216+Guiners@users.noreply.github.com> Date: Fri, 7 Nov 2025 10:41:44 +0100 Subject: [PATCH 4/9] Update genai/test/imggen-raw-reference-with-txt-img.test.js Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- genai/test/imggen-raw-reference-with-txt-img.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/genai/test/imggen-raw-reference-with-txt-img.test.js b/genai/test/imggen-raw-reference-with-txt-img.test.js index 1ff747850d..c185333547 100644 --- a/genai/test/imggen-raw-reference-with-txt-img.test.js +++ b/genai/test/imggen-raw-reference-with-txt-img.test.js @@ -23,7 +23,7 @@ const sample = require('../image-generation/imggen-raw-reference-with-txt-img'); const {delay} = require('./util'); const {createOutputGcsUri} = require('./imggen-util'); describe('imggen-raw-reference-with-txt-img', () => { - it('should return a GCS URI string', async function () { + it('should return an array of generated image URIs', async function () { this.timeout(180000); this.retries(4); const output = await createOutputGcsUri(); From 7da5c3d48bc8fdbba49a47ffb90903a18e756b65 Mon Sep 17 00:00:00 2001 From: Guiners Date: Fri, 7 Nov 2025 10:58:08 +0100 Subject: [PATCH 5/9] codereview fix --- genai/package.json | 4 +++- genai/test/imggen-util.js | 7 +------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/genai/package.json b/genai/package.json index 2c370bd447..f0f5a458df 100644 --- a/genai/package.json +++ b/genai/package.json @@ -13,13 +13,15 @@ "test": "c8 mocha -p -j 2 --timeout 2400000 test/*.test.js test/**/*.test.js" }, "dependencies": { + "@google-cloud/storage": "^7.17.3", "@google/genai": "1.20.0", "axios": "^1.6.2", + "date-fns": "^4.1.0", "google-auth-library": "^10.3.0", "luxon": "^3.7.1", - "proxyquire": "^2.1.3", "node-fetch": "^3.3.2", "openai": "^5.19.1", + "proxyquire": "^2.1.3", "supertest": "^7.0.0" }, "devDependencies": { diff --git a/genai/test/imggen-util.js b/genai/test/imggen-util.js index d59b1f3a12..36e77bb2d8 100644 --- a/genai/test/imggen-util.js +++ b/genai/test/imggen-util.js @@ -15,12 +15,7 @@ const {Storage} = require('@google-cloud/storage'); const {format} = require('date-fns'); -// local -const gcsOutputBucket = - 'example-cloud-bucket-5439474/nodejs-docs-samples-tests'; - -//uncomment -// const gcsOutputBucket = "nodejs-docs-samples-tests"; +const gcsOutputBucket = 'nodejs-docs-samples-tests'; module.exports.createOutputGcsUri = async function () { const prefix = `text_output/${format(new Date(), 'yyyy-MM-dd-HH-mm-ss')}`; From c1a6add6040f2c5117f5122a410370a4188b8945 Mon Sep 17 00:00:00 2001 From: Guiners Date: Fri, 7 Nov 2025 11:01:22 +0100 Subject: [PATCH 6/9] codereview fix --- genai/image-generation/imggen-raw-reference-with-txt-img.js | 1 + 1 file changed, 1 insertion(+) diff --git a/genai/image-generation/imggen-raw-reference-with-txt-img.js b/genai/image-generation/imggen-raw-reference-with-txt-img.js index 9e7ca07ef4..ff22f4cb83 100644 --- a/genai/image-generation/imggen-raw-reference-with-txt-img.js +++ b/genai/image-generation/imggen-raw-reference-with-txt-img.js @@ -28,6 +28,7 @@ async function generateImage( location = GOOGLE_CLOUD_LOCATION ) { const client = new GoogleGenAI({ + vertexai: true, project: projectId, location: location, }); From e521e1a6386de5298a4508dc067f23b0991d3f29 Mon Sep 17 00:00:00 2001 From: Guiners Date: Wed, 12 Nov 2025 14:26:38 +0100 Subject: [PATCH 7/9] fixing failed tests --- .../imggen-canny-ctrl-type-with-txt-img.js | 1 + ...gen-subj-refer-ctrl-refer-with-txt-imgs.js | 3 +-- .../imggen-raw-reference-with-txt-img.test.js | 27 ++++++++++++------- ...en-scribble-ctrl-type-with-txt-img.test.js | 27 ++++++++++++------- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/genai/image-generation/imggen-canny-ctrl-type-with-txt-img.js b/genai/image-generation/imggen-canny-ctrl-type-with-txt-img.js index d9d2775aab..1a09d616b4 100644 --- a/genai/image-generation/imggen-canny-ctrl-type-with-txt-img.js +++ b/genai/image-generation/imggen-canny-ctrl-type-with-txt-img.js @@ -46,6 +46,7 @@ async function generateImage( const response = await client.models.editImage({ model: 'imagen-3.0-capability-001', + // The '[1]' in the prompt corresponds to the controlReferenceImage.referenceId above. prompt: 'a watercolor painting of a red car[1] driving on a road', referenceImages: [controlReferenceImage], config: { diff --git a/genai/image-generation/imggen-subj-refer-ctrl-refer-with-txt-imgs.js b/genai/image-generation/imggen-subj-refer-ctrl-refer-with-txt-imgs.js index 19946ec8fd..e98b9a97b4 100644 --- a/genai/image-generation/imggen-subj-refer-ctrl-refer-with-txt-imgs.js +++ b/genai/image-generation/imggen-subj-refer-ctrl-refer-with-txt-imgs.js @@ -60,8 +60,7 @@ async function generateImage( const response = await client.models.editImage({ model: 'imagen-3.0-capability-001', - prompt: - `a portrait of a woman[1] in the pose of the control image[2]in a watercolor style by a professional artist, + prompt: `a portrait of a woman[1] in the pose of the control image[2]in a watercolor style by a professional artist, light and low-contrast stokes, bright pastel colors, a warm atmosphere, clean background, grainy paper, bold visible brushstrokes, patchy details`, referenceImages: [subjectReferenceImage, controlReferenceImage], diff --git a/genai/test/imggen-raw-reference-with-txt-img.test.js b/genai/test/imggen-raw-reference-with-txt-img.test.js index c185333547..e4b7ab3dc8 100644 --- a/genai/test/imggen-raw-reference-with-txt-img.test.js +++ b/genai/test/imggen-raw-reference-with-txt-img.test.js @@ -24,15 +24,24 @@ const {delay} = require('./util'); const {createOutputGcsUri} = require('./imggen-util'); describe('imggen-raw-reference-with-txt-img', () => { it('should return an array of generated image URIs', async function () { - this.timeout(180000); - this.retries(4); + this.timeout(600000); + this.retries(3); + const output = await createOutputGcsUri(); - console.log(output.uri); - await delay(this.test); - const generatedFileNames = await sample.generateImage( - output.uri, - projectId - ); - assert(generatedFileNames.length > 0); + console.log('Output GCS URI:', output.uri); + + try { + await delay(this.test); + const generatedFileNames = await sample.generateImage( + output.uri, + projectId + ); + console.log('Generated files:', generatedFileNames); + + assert(generatedFileNames.length > 0); + } catch (err) { + console.error('Image generation failed:', err); + throw err; + } }); }); diff --git a/genai/test/imggen-scribble-ctrl-type-with-txt-img.test.js b/genai/test/imggen-scribble-ctrl-type-with-txt-img.test.js index f8415225d1..982479b0cd 100644 --- a/genai/test/imggen-scribble-ctrl-type-with-txt-img.test.js +++ b/genai/test/imggen-scribble-ctrl-type-with-txt-img.test.js @@ -24,15 +24,24 @@ const {createOutputGcsUri} = require('./imggen-util'); describe('imggen-scribble-ctrl-type-with-txt-img', async () => { it('should generate images from a text prompt with control reference image', async function () { - this.timeout(180000); - this.retries(4); + this.timeout(600000); + this.retries(3); + const output = await createOutputGcsUri(); - console.log(output.uri); - await delay(this.test); - const generatedFileNames = await sample.generateImage( - output.uri, - projectId - ); - assert(generatedFileNames.length > 0); + console.log('Output GCS URI:', output.uri); + + try { + await delay(this.test); + const generatedFileNames = await sample.generateImage( + output.uri, + projectId + ); + console.log('Generated files:', generatedFileNames); + + assert(generatedFileNames.length > 0); + } catch (err) { + console.error('Image generation failed:', err); + throw err; + } }); }); From e882b5cf28321429b69eeb5fdb04f7b0f623baf0 Mon Sep 17 00:00:00 2001 From: Guiners Date: Thu, 13 Nov 2025 11:11:06 +0100 Subject: [PATCH 8/9] codereview fix --- .../image-generation/imggen-canny-ctrl-type-with-txt-img.js | 4 ++-- genai/test/imggen-canny-ctrl-type-with-txt-img.test.js | 1 + genai/test/imggen-raw-reference-with-txt-img.test.js | 3 ++- genai/test/imggen-util.js | 5 +++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/genai/image-generation/imggen-canny-ctrl-type-with-txt-img.js b/genai/image-generation/imggen-canny-ctrl-type-with-txt-img.js index 1a09d616b4..e1a94a29b5 100644 --- a/genai/image-generation/imggen-canny-ctrl-type-with-txt-img.js +++ b/genai/image-generation/imggen-canny-ctrl-type-with-txt-img.js @@ -57,11 +57,11 @@ async function generateImage( outputGcsUri: outputGcsUri, }, }); - console.log(response.generatedImages); + console.log(response.generatedImages[0].image.gcsUri); // Example response: // gs://your-bucket/your-prefix - return response.generatedImages; + return response.generatedImages[0].image.gcsUri; } // [END googlegenaisdk_imggen_canny_ctrl_type_with_txt_img] diff --git a/genai/test/imggen-canny-ctrl-type-with-txt-img.test.js b/genai/test/imggen-canny-ctrl-type-with-txt-img.test.js index e059c90a7e..a9c43af307 100644 --- a/genai/test/imggen-canny-ctrl-type-with-txt-img.test.js +++ b/genai/test/imggen-canny-ctrl-type-with-txt-img.test.js @@ -22,6 +22,7 @@ const projectId = process.env.CAIP_PROJECT_ID; const sample = require('../image-generation/imggen-canny-ctrl-type-with-txt-img'); const {delay} = require('./util'); const {createOutputGcsUri} = require('./imggen-util'); + describe('imggen-canny-ctrl-type-with-txt-img', () => { it('should return an array of generated image URIs', async function () { this.timeout(180000); diff --git a/genai/test/imggen-raw-reference-with-txt-img.test.js b/genai/test/imggen-raw-reference-with-txt-img.test.js index e4b7ab3dc8..bbb54fb9db 100644 --- a/genai/test/imggen-raw-reference-with-txt-img.test.js +++ b/genai/test/imggen-raw-reference-with-txt-img.test.js @@ -22,10 +22,11 @@ const projectId = process.env.CAIP_PROJECT_ID; const sample = require('../image-generation/imggen-raw-reference-with-txt-img'); const {delay} = require('./util'); const {createOutputGcsUri} = require('./imggen-util'); + describe('imggen-raw-reference-with-txt-img', () => { it('should return an array of generated image URIs', async function () { this.timeout(600000); - this.retries(3); + // this.retries(3); const output = await createOutputGcsUri(); console.log('Output GCS URI:', output.uri); diff --git a/genai/test/imggen-util.js b/genai/test/imggen-util.js index 36e77bb2d8..2e6770a65a 100644 --- a/genai/test/imggen-util.js +++ b/genai/test/imggen-util.js @@ -15,8 +15,9 @@ const {Storage} = require('@google-cloud/storage'); const {format} = require('date-fns'); -const gcsOutputBucket = 'nodejs-docs-samples-tests'; - +// const gcsOutputBucket = 'nodejs-docs-samples-tests'; +const gcsOutputBucket = + 'example-cloud-bucket-5439474/nodejs-docs-samples-tests'; module.exports.createOutputGcsUri = async function () { const prefix = `text_output/${format(new Date(), 'yyyy-MM-dd-HH-mm-ss')}`; const gcsUri = `gs://${gcsOutputBucket}/${prefix}`; From fa57672d3d77ec75cf92f18506cc1012c420e6e3 Mon Sep 17 00:00:00 2001 From: Guiners Date: Thu, 13 Nov 2025 15:13:40 +0100 Subject: [PATCH 9/9] fixing tests --- genai/test/imggen-canny-ctrl-type-with-txt-img.test.js | 4 +++- genai/test/imggen-raw-reference-with-txt-img.test.js | 6 ++++-- genai/test/imggen-scribble-ctrl-type-with-txt-img.test.js | 4 +++- genai/test/imggen-style-reference-with-txt-img.test.js | 4 +++- .../test/imggen-subj-refer-ctrl-refer-with-txt-imgs.test.js | 4 +++- genai/test/imggen-util.js | 5 ++--- 6 files changed, 18 insertions(+), 9 deletions(-) diff --git a/genai/test/imggen-canny-ctrl-type-with-txt-img.test.js b/genai/test/imggen-canny-ctrl-type-with-txt-img.test.js index a9c43af307..a72409d607 100644 --- a/genai/test/imggen-canny-ctrl-type-with-txt-img.test.js +++ b/genai/test/imggen-canny-ctrl-type-with-txt-img.test.js @@ -20,6 +20,7 @@ const {describe, it} = require('mocha'); const projectId = process.env.CAIP_PROJECT_ID; const sample = require('../image-generation/imggen-canny-ctrl-type-with-txt-img'); +const location = 'us-central1'; const {delay} = require('./util'); const {createOutputGcsUri} = require('./imggen-util'); @@ -32,7 +33,8 @@ describe('imggen-canny-ctrl-type-with-txt-img', () => { await delay(this.test); const generatedFileNames = await sample.generateImage( output.uri, - projectId + projectId, + location ); assert(generatedFileNames.length > 0); }); diff --git a/genai/test/imggen-raw-reference-with-txt-img.test.js b/genai/test/imggen-raw-reference-with-txt-img.test.js index bbb54fb9db..39510ae541 100644 --- a/genai/test/imggen-raw-reference-with-txt-img.test.js +++ b/genai/test/imggen-raw-reference-with-txt-img.test.js @@ -22,11 +22,12 @@ const projectId = process.env.CAIP_PROJECT_ID; const sample = require('../image-generation/imggen-raw-reference-with-txt-img'); const {delay} = require('./util'); const {createOutputGcsUri} = require('./imggen-util'); +const location = 'us-central1'; describe('imggen-raw-reference-with-txt-img', () => { it('should return an array of generated image URIs', async function () { this.timeout(600000); - // this.retries(3); + this.retries(3); const output = await createOutputGcsUri(); console.log('Output GCS URI:', output.uri); @@ -35,7 +36,8 @@ describe('imggen-raw-reference-with-txt-img', () => { await delay(this.test); const generatedFileNames = await sample.generateImage( output.uri, - projectId + projectId, + location ); console.log('Generated files:', generatedFileNames); diff --git a/genai/test/imggen-scribble-ctrl-type-with-txt-img.test.js b/genai/test/imggen-scribble-ctrl-type-with-txt-img.test.js index 982479b0cd..6f0d7f55bd 100644 --- a/genai/test/imggen-scribble-ctrl-type-with-txt-img.test.js +++ b/genai/test/imggen-scribble-ctrl-type-with-txt-img.test.js @@ -21,6 +21,7 @@ const projectId = process.env.CAIP_PROJECT_ID; const sample = require('../image-generation/imggen-scribble-ctrl-type-with-txt-img'); const {delay} = require('./util'); const {createOutputGcsUri} = require('./imggen-util'); +const location = 'us-central1'; describe('imggen-scribble-ctrl-type-with-txt-img', async () => { it('should generate images from a text prompt with control reference image', async function () { @@ -34,7 +35,8 @@ describe('imggen-scribble-ctrl-type-with-txt-img', async () => { await delay(this.test); const generatedFileNames = await sample.generateImage( output.uri, - projectId + projectId, + location ); console.log('Generated files:', generatedFileNames); diff --git a/genai/test/imggen-style-reference-with-txt-img.test.js b/genai/test/imggen-style-reference-with-txt-img.test.js index 0e96371d0e..7015d1e519 100644 --- a/genai/test/imggen-style-reference-with-txt-img.test.js +++ b/genai/test/imggen-style-reference-with-txt-img.test.js @@ -21,6 +21,7 @@ const projectId = process.env.CAIP_PROJECT_ID; const sample = require('../image-generation/imggen-style-reference-with-txt-img'); const {delay} = require('./util'); const {createOutputGcsUri} = require('./imggen-util'); +const location = 'us-central1'; describe('imggen-style-reference-with-txt-img', async () => { it('should generate images from a text prompt with style reference', async function () { @@ -31,7 +32,8 @@ describe('imggen-style-reference-with-txt-img', async () => { await delay(this.test); const generatedFileNames = await sample.generateImage( output.uri, - projectId + projectId, + location ); assert(generatedFileNames.length > 0); }); diff --git a/genai/test/imggen-subj-refer-ctrl-refer-with-txt-imgs.test.js b/genai/test/imggen-subj-refer-ctrl-refer-with-txt-imgs.test.js index 969a24127a..4b9c0949b1 100644 --- a/genai/test/imggen-subj-refer-ctrl-refer-with-txt-imgs.test.js +++ b/genai/test/imggen-subj-refer-ctrl-refer-with-txt-imgs.test.js @@ -21,6 +21,7 @@ const projectId = process.env.CAIP_PROJECT_ID; const sample = require('../image-generation/imggen-subj-refer-ctrl-refer-with-txt-imgs'); const {delay} = require('./util'); const {createOutputGcsUri} = require('./imggen-util'); +const location = 'us-central1'; describe('imggen-subj-refer-ctrl-refer-with-txt-imgs', async () => { it('should generate images from a text prompt with subject reference image and control reference image', async function () { @@ -31,7 +32,8 @@ describe('imggen-subj-refer-ctrl-refer-with-txt-imgs', async () => { await delay(this.test); const generatedFileNames = await sample.generateImage( output.uri, - projectId + projectId, + location ); assert(generatedFileNames.length > 0); }); diff --git a/genai/test/imggen-util.js b/genai/test/imggen-util.js index 2e6770a65a..36e77bb2d8 100644 --- a/genai/test/imggen-util.js +++ b/genai/test/imggen-util.js @@ -15,9 +15,8 @@ const {Storage} = require('@google-cloud/storage'); const {format} = require('date-fns'); -// const gcsOutputBucket = 'nodejs-docs-samples-tests'; -const gcsOutputBucket = - 'example-cloud-bucket-5439474/nodejs-docs-samples-tests'; +const gcsOutputBucket = 'nodejs-docs-samples-tests'; + module.exports.createOutputGcsUri = async function () { const prefix = `text_output/${format(new Date(), 'yyyy-MM-dd-HH-mm-ss')}`; const gcsUri = `gs://${gcsOutputBucket}/${prefix}`;