Imagen en Vertex AI ofrece una herramienta de reescritura de instrucciones basada en LLM, también conocida como reescritor de instrucciones. El reescritor de instrucciones te ayuda a obtener imágenes de mayor calidad agregando más detalles a tu instrucción.
Si inhabilitas el reescritor de instrucciones, es posible que se vea afectada la calidad de las imágenes y el grado en que el resultado se asemeja a la instrucción que proporcionaste. Esta función está habilitada de forma predeterminada para las siguientes versiones del modelo:
imagen-4.0-generate-001
imagen-4.0-fast-generate-001
imagen-4.0-ultra-generate-001
imagen-3.0-generate-002
La respuesta de la API entrega la instrucción reescrita solo si la instrucción original tiene menos de 30 palabras.
Usa el reescritor de instrucciones
Para usar el reescritor de instrucciones, haz lo siguiente:
Console
En la Google Cloud consola, ve a la página Vertex AI > Media Studio.
MODEL_VERSION: Es la versión del modelo de generación de imágenes que se usará.
Para obtener más información sobre las versiones y los atributos del modelo, consulta las versiones del modelo.
LOCATION: La región del proyecto. Por ejemplo, us-central1, europe-west2 o asia-northeast3. Para obtener una lista de las regiones disponibles, consulta IA generativa en ubicaciones de Vertex AI.
TEXT_PROMPT: La instrucción de texto que guía qué imágenes genera el modelo. Antes de generar las imágenes, esta instrucción base se mejora con más detalles y un lenguaje descriptivo a través de la herramienta de reformulación de instrucciones basada en LLM.
IMAGE_COUNT: Es un número entero que describe la cantidad de imágenes que se generarán. Los valores aceptados son de 1 a 4. El valor predeterminado es 4.
PROMPT_SETTING: Es un valor booleano. true habilita las instrucciones mejoradas y false las inhabilita. El valor predeterminado es true.
Método HTTP y URL:
POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict
Con la mejora de instrucciones habilitada, la respuesta incluye un campo prompt adicional que muestra la instrucción mejorada y su imagen generada asociada:
Por ejemplo, la siguiente respuesta de muestra es para una solicitud con "sampleCount": 2 y "prompt": "A raccoon wearing formal
clothes, wearing a top hat. Oil painting in the style of Vincent Van
Gogh.". La respuesta muestra dos objetos de predicción, cada uno con su instrucción mejorada y los bytes de imagen generados codificados en base64.
{
"predictions": [
{
"mimeType": "image/png",
"prompt": "An oil painting in the style of Vincent van Gogh,
depicting a raccoon adorned in a finely tailored tuxedo, complete with a
crisp white shirt and a bow tie. The raccoon also sports a classic top
hat, perched jauntily on its head. The painting uses thick, swirling
brushstrokes characteristic of van Gogh, with vibrant hues of blue,
yellow, and green in the background, contrasting with the dark tones of
the raccoon's attire. The light source is subtly placed, casting a
dramatic shadow of the raccoon's attire onto the surface it sits upon,
further enhancing the depth and dimensionality of the composition. The
overall impression is one of a whimsical and sophisticated character, a
raccoon elevated to a higher class through its formal attire, rendered
in van Gogh's iconic style.",
"bytesBase64Encoded": "BASE64_IMG_BYTES"
},
{
"mimeType": "image/png",
"prompt": "An oil painting in the style of Vincent van Gogh featuring
a raccoon in a dapper suit, complete with a black jacket, crisp white
shirt, and a black bow tie. The raccoon is wearing a black top hat,
adding a touch of elegance to its ensemble. The painting is rendered
with characteristic van Gogh brushwork, utilizing thick, impasto strokes
of color. The background is a swirl of blues, greens, and yellows,
creating a vibrant yet slightly chaotic atmosphere that contrasts with
the raccoon's formal attire. The lighting is dramatic, casting sharp
shadows and highlighting the textures of the fabric and the raccoon's
fur, enhancing the sense of realism within the fantastical scene. The
composition focuses on the raccoon's proud posture, highlighting the
whimsical contrast of a wild animal dressed in formal attire, captured
in the unique artistic language of van Gogh. ",
"bytesBase64Encoded": "BASE64_IMG_BYTES"
}
]
}
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[],[],null,["# Use prompt rewriter\n\n| **Caution:** Starting on June 24, 2025, Imagen versions 1 and 2 are deprecated. Imagen models `imagegeneration@002`, `imagegeneration@005`, and `imagegeneration@006` will be removed on September 24, 2025 . For more information about migrating to Imagen 3, see [Migrate to\n| Imagen 3](/vertex-ai/generative-ai/docs/image/migrate-to-imagen-3).\n\n\u003cbr /\u003e\n\n\n[Try image generation (Vertex AI Studio)](https://console.cloud.google.com/vertex-ai/studio/media/generate;tab=image)\n\n[Try Imagen in a Colab](https://colab.research.google.com/github/GoogleCloudPlatform/generative-ai/blob/main/vision/getting-started/imagen4_image_generation.ipynb)\n\nImagen on Vertex AI offers an LLM-based prompt rewriting tool, also known as a\nprompt rewriter. The prompt rewriter helps you obtain higher quality output\nimages by adding more detail to your prompt.\n\nIf you disable the prompt rewriter, the quality of the images and how well the\noutput resembles the prompt that you supplied may be impacted. This feature is\nenabled by default for the following model versions:\n\n- `imagen-4.0-generate-001`\n- `imagen-4.0-fast-generate-001`\n- `imagen-4.0-ultra-generate-001`\n- `imagen-3.0-generate-002`\n\nThe rewritten prompt is delivered by API response only if the original prompt\nis fewer than 30 words long.\n| **Important:** `imagen-4.0-fast-generate-001` may generate undesireable results if the prompt is complex and you use enhanced prompts. To fix this, avoid using **Help me write** in Google Cloud console, or set `enhancePrompt` to `false`.\n\nUse the prompt rewriter\n-----------------------\n\nTo use the prompt rewriter, do the following: \n\n### Console\n\n1. In the Google Cloud console, go to the **Vertex AI \\\u003e Media\n Studio** page.\n\n [Go to Media\n Studio](https://console.cloud.google.com/vertex-ai/studio/media/generate;tab=image)\n2. Click **Imagen**. The Imagen Media Studio image generation page is\n displayed.\n\n3. In the **Settings** panel, adjust the following options:\n\n - **Model**: Choose a model from the available options.\n\n For more information about available models, see [Imagen\n models](/vertex-ai/generative-ai/docs/models#imagen-models)\n - **Number of results** : Adjust the slider or enter a value between\n **1** and **4**.\n\n - In the **Negative prompt** box, enter a prompt that describes what\n you don't want generated in the image.\n\n4. In the **Write your prompt** box, click **Help me write**.\n\n The **Enhance my prompt** window is displayed.\n5. In the **Current prompt** box, write your prompt, and then click\n **Enhance**.\n\n The rewritten prompt is displayed in the **Enhanced prompt** box. You\n can edit the enhanced prompt or use it as displayed.\n6. Click **Insert** to use the displayed prompt.\n\n The prompt is inserted into the **Write your prompt** box.\n7. Click send **Generate**.\n\n### REST\n\n\nBefore using any of the request data,\nmake the following replacements:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: Your Google Cloud [project ID](/resource-manager/docs/creating-managing-projects#identifiers).\n- \u003cvar translate=\"no\"\u003eMODEL_VERSION\u003c/var\u003e: The image generation model version to use.\n\n For more information about model versions and features, see [model versions](#model-versions).\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: Your project's region. For example, `us-central1`, `europe-west2`, or `asia-northeast3`. For a list of available regions, see [Generative AI on Vertex AI locations](/vertex-ai/generative-ai/docs/learn/locations-genai).\n- \u003cvar translate=\"no\"\u003eTEXT_PROMPT\u003c/var\u003e: The text prompt that guides what images the model generates. Before images are generated, this base prompt is enhanced with more detail and descripitive language using the LLM-based prompt rewriting tool.\n- \u003cvar translate=\"no\"\u003eIMAGE_COUNT\u003c/var\u003e: An integer, describing the number of images to generate. The accepted values are `1`-`4`. The default value is `4`.\n- \u003cvar translate=\"no\"\u003ePROMPT_SETTING\u003c/var\u003e: A boolean value, `true` enables enhanced prompts and `false` disables enhanced prompts. The default value is `true`.\n\n\nHTTP method and URL:\n\n```\nPOST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict\n```\n\n\nRequest JSON body:\n\n```\n{\n \"instances\": [\n {\n \"prompt\": \"TEXT_PROMPT\"\n }\n ],\n \"parameters\": {\n \"sampleCount\": IMAGE_COUNT,\n \"enhancePrompt\": \u003cvar translate=\"no\"\u003ePROMPT_SETTING\u003c/var\u003e\n }\n}\n```\n\nTo send your request, choose one of these options: \n\n#### curl\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) , or by using [Cloud Shell](/shell/docs), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nSave the request body in a file named `request.json`,\nand execute the following command:\n\n```\ncurl -X POST \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"Content-Type: application/json; charset=utf-8\" \\\n -d @request.json \\\n \"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict\"\n```\n\n#### PowerShell\n\n| **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](/sdk/gcloud/reference/init) or [`gcloud auth login`](/sdk/gcloud/reference/auth/login) . You can check the currently active account by running [`gcloud auth list`](/sdk/gcloud/reference/auth/list).\n\n\nSave the request body in a file named `request.json`,\nand execute the following command:\n\n```\n$cred = gcloud auth print-access-token\n$headers = @{ \"Authorization\" = \"Bearer $cred\" }\n\nInvoke-WebRequest `\n -Method POST `\n -Headers $headers `\n -ContentType: \"application/json; charset=utf-8\" `\n -InFile request.json `\n -Uri \"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict\" | Select-Object -Expand Content\n```\nWith prompt enhancement enabled, the response includes an additional `prompt` field that shows the enhanced prompt and its associated generated image: \n\n```json\n {\n \"predictions\": [\n {\n \"mimeType\": \"\u003cvar translate=\"no\"\u003eMIME_TYPE\u003c/var\u003e\",\n \"prompt\": \"\u003cvar translate=\"no\"\u003eENHANCED_PROMPT_1\u003c/var\u003e\",\n \"bytesBase64Encoded\": \"\u003cvar translate=\"no\"\u003eBASE64_IMG_BYTES_1\u003c/var\u003e\"\n },\n {\n \"mimeType\": \"\u003cvar translate=\"no\"\u003eMIME_TYPE\u003c/var\u003e\",\n \"prompt\": \"\u003cvar translate=\"no\"\u003eENHANCED_PROMPT_2\u003c/var\u003e\",\n \"bytesBase64Encoded\": \"\u003cvar translate=\"no\"\u003eBASE64_IMG_BYTES_2\u003c/var\u003e\"\n }\n ]\n }\n```\n\n\nFor example, the following sample response is for a request with\n`\"sampleCount\": 2` and `\"prompt\": \"A raccoon wearing formal\nclothes, wearing a top hat. Oil painting in the style of Vincent Van\nGogh.\"`. The response returns two prediction objects, each with their\nenhanced prompt and the generated image bytes base64-encoded.\n\n```\n{\n \"predictions\": [\n {\n \"mimeType\": \"image/png\",\n \"prompt\": \"\u003cvar translate=\"no\"\u003eAn oil painting in the style of Vincent van Gogh,\n depicting a raccoon adorned in a finely tailored tuxedo, complete with a\n crisp white shirt and a bow tie. The raccoon also sports a classic top\n hat, perched jauntily on its head. The painting uses thick, swirling\n brushstrokes characteristic of van Gogh, with vibrant hues of blue,\n yellow, and green in the background, contrasting with the dark tones of\n the raccoon's attire. The light source is subtly placed, casting a\n dramatic shadow of the raccoon's attire onto the surface it sits upon,\n further enhancing the depth and dimensionality of the composition. The\n overall impression is one of a whimsical and sophisticated character, a\n raccoon elevated to a higher class through its formal attire, rendered\n in van Gogh's iconic style.\u003c/var\u003e\",\n \"bytesBase64Encoded\": \"BASE64_IMG_BYTES\"\n },\n {\n \"mimeType\": \"image/png\",\n \"prompt\": \"\u003cvar translate=\"no\"\u003eAn oil painting in the style of Vincent van Gogh featuring\n a raccoon in a dapper suit, complete with a black jacket, crisp white\n shirt, and a black bow tie. The raccoon is wearing a black top hat,\n adding a touch of elegance to its ensemble. The painting is rendered\n with characteristic van Gogh brushwork, utilizing thick, impasto strokes\n of color. The background is a swirl of blues, greens, and yellows,\n creating a vibrant yet slightly chaotic atmosphere that contrasts with\n the raccoon's formal attire. The lighting is dramatic, casting sharp\n shadows and highlighting the textures of the fabric and the raccoon's\n fur, enhancing the sense of realism within the fantastical scene. The\n composition focuses on the raccoon's proud posture, highlighting the\n whimsical contrast of a wild animal dressed in formal attire, captured\n in the unique artistic language of van Gogh. \u003c/var\u003e\",\n \"bytesBase64Encoded\": \"BASE64_IMG_BYTES\"\n }\n ]\n}\n```\n\n\u003cbr /\u003e\n\nWhat's next\n-----------\n\n- [Set text prompt language](/vertex-ai/generative-ai/docs/image/set-text-prompt-language)\n- [Configure aspect ratio](/vertex-ai/generative-ai/docs/image/configure-aspect-ratio)\n- [Omit content using a negative prompt](/vertex-ai/generative-ai/docs/image/omit-content-using-a-negative-prompt)\n- [Generate deterministic images](/vertex-ai/generative-ai/docs/image/generate-deterministic-images)"]]