Imagen sur Vertex AI propose un outil de réécriture des requêtes basé sur un LLM, également appelé réécrivain de requêtes. Le réécriveur de requêtes vous aide à obtenir des images de meilleure qualité en ajoutant plus de détails à votre requête.
Si vous désactivez le réécriveur de requêtes, la qualité des images et la fidélité de la sortie par rapport à la requête que vous avez fournie peuvent être affectées. Cette fonctionnalité est activée par défaut pour les versions de modèle suivantes :
imagen-4.0-generate-001
imagen-4.0-fast-generate-001
imagen-4.0-ultra-generate-001
imagen-3.0-generate-002
La requête reformulée n'est envoyée par la réponse de l'API que si la requête d'origine contient moins de 30 mots.
Utiliser l'outil de reformulation de requêtes
Pour utiliser le réécriveur de requêtes :
Console
Dans la console Google Cloud , accédez à la page Vertex AI>Media Studio.
MODEL_VERSION : version du modèle de génération d'images à utiliser.
Pour en savoir plus sur les versions et les fonctionnalités des modèles, consultez Versions de modèles.
LOCATION : région de votre projet. (us-central1, europe-west2 ou asia-northeast3, par exemple). Pour obtenir la liste des régions disponibles, consultez IA générative sur les emplacements Vertex AI.
TEXT_PROMPT : la requête textuelle qui guide le modèle pour la génération d'images. Avant la génération des images, cette requête de base est améliorée avec un langage plus détaillé et descriptif à l'aide de l'outil de reformulation de requête basé sur un LLM.
IMAGE_COUNT : entier décrivant le nombre d'images à générer. Les valeurs acceptées sont comprises entre 1 et 4. La valeur par défaut est 4.
PROMPT_SETTING : valeur booléenne. true active les requêtes améliorées et false les désactive. La valeur par défaut est true.
Méthode HTTP et URL :
POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict
Lorsque l'amélioration des requêtes est activée, la réponse inclut un champ prompt supplémentaire qui affiche la requête améliorée et l'image générée qui lui est associée :
Par exemple, l'exemple de réponse suivant concerne une requête avec "sampleCount": 2 et "prompt": "A raccoon wearing formal
clothes, wearing a top hat. Oil painting in the style of Vincent Van
Gogh.". La réponse renvoie deux objets de prédiction, chacun avec leur requête améliorée et les octets d'image générés encodés 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"
}
]
}
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/04 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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)"]]