diff --git a/tests/unit/aiplatform/test_vision_models.py b/tests/unit/aiplatform/test_vision_models.py index 80c366188a..ba13f91116 100644 --- a/tests/unit/aiplatform/test_vision_models.py +++ b/tests/unit/aiplatform/test_vision_models.py @@ -251,7 +251,7 @@ def test_generate_images(self): actual_parameters = predict_kwargs["parameters"] actual_instance = predict_kwargs["instances"][0] assert actual_instance["prompt"] == prompt1 - assert actual_instance["negativePrompt"] == negative_prompt1 + assert actual_parameters["negativePrompt"] == negative_prompt1 # TODO(b/295946075) The service stopped supporting image sizes. # assert actual_parameters["sampleImageSize"] == str(max(width, height)) # assert actual_parameters["aspectRatio"] == f"{width}:{height}" diff --git a/vertexai/vision_models/_vision_models.py b/vertexai/vision_models/_vision_models.py index 4cd838d4f2..5d803103f5 100644 --- a/vertexai/vision_models/_vision_models.py +++ b/vertexai/vision_models/_vision_models.py @@ -174,10 +174,6 @@ def _generate_images( "number_of_images_in_batch": number_of_images, } - if negative_prompt: - instance["negativePrompt"] = negative_prompt - shared_generation_parameters["negative_prompt"] = negative_prompt - if base_image: base_image_base64 = ( base_image._as_base64_string() @@ -207,6 +203,9 @@ def _generate_images( parameters["aspectRatio"] = f"{width}:{height}" parameters["sampleCount"] = number_of_images + if negative_prompt: + parameters["negativePrompt"] = negative_prompt + shared_generation_parameters["negative_prompt"] = negative_prompt if seed is not None: # Note: String seed and numerical seed give different results