Imagen on Vertex AI 提供基于 LLM 的提示重写工具,也称为提示重写器。提示重写器可通过在提示中添加更多细节来帮助您获得更高质量的输出图片。
如果您停用提示重写器,图片的质量以及输出内容与您提供的提示的相似程度可能会受到影响。对于以下模型版本,此功能默认处于启用状态:
imagen-4.0-generate-preview-06-06
(预览版)imagen-4.0-fast-generate-preview-06-06
(预览版)imagen-4.0-ultra-generate-preview-06-06
(预览版)imagen-3.0-generate-002
仅当原始提示的长度少于 30 个字词时,API 响应才会传送重写的提示。
使用提示重写器
如需使用提示重写器,请执行以下操作:
控制台
在 Google Cloud 控制台中,依次前往 Vertex AI > Media Studio 页面。
点击 Imagen。系统会显示 Imagen Media Studio 图片生成页面。
在设置面板中,调整以下选项:
模型:从可用选项中选择一个模型。
如需详细了解可用模型,请参阅 Imagen 模型
结果数量:调整滑块或输入介于 1 和 4 之间的值。
在负面提示框中,输入描述您不希望在图片中生成的内容的提示。
在撰写提示框中,点击帮我写。
系统会显示增强提示窗口。
在当前提示框中,撰写提示,然后点击优化。
重写的提示会显示在增强提示框中。您可以修改增强型提示,也可以按显示的原样使用。
点击插入以使用显示的提示。
系统会将提示插入到撰写提示框中。
点击
生成。
REST
在使用任何请求数据之前,请先进行以下替换:
- PROJECT_ID:您的 Google Cloud 项目 ID。
- MODEL_VERSION:要使用的图片生成模型版本。
如需详细了解模型版本和功能,请参阅模型版本。
- LOCATION:您的项目的区域。 例如
us-central1
、europe-west2
或asia-northeast3
。如需查看可用区域的列表,请参阅 Vertex AI 上的生成式 AI 位置。 - TEXT_PROMPT:用于引导模型生成什么图片的文本提示。在生成图片之前,使用基于 LLM 的重写提示工具,通过更详细的描述性语言增强此基础提示。
- IMAGE_COUNT:生成的图片数量。 接受的整数值:1-4。 默认值:4。
enhancePrompt
- 一个布尔值,用于启用基于 LLM 的提示增强功能。默认情况下,此值设置为true
。
HTTP 方法和网址:
POST http://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict
请求 JSON 正文:
{ "instances": [ { "prompt": "TEXT_PROMPT" } ], "parameters": { "sampleCount": IMAGE_COUNT, "enhancePrompt": true } }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"http://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict"
PowerShell
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "http://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/MODEL_VERSION:predict" | Select-Object -Expand Content
prompt
字段,用于显示增强的提示及其关联的生成图片:
{ "predictions": [ { "mimeType": "MIME_TYPE", "prompt": "ENHANCED_PROMPT_1", "bytesBase64Encoded": "BASE64_IMG_BYTES_1" }, { "mimeType": "MIME_TYPE", "prompt": "ENHANCED_PROMPT_2", "bytesBase64Encoded": "BASE64_IMG_BYTES_2" } ] }
例如,以下示例回答适用于具有 "sampleCount": 2
和 "prompt": "A raccoon wearing formal clothes, wearing a top
hat. Oil painting in the style of Vincent Van Gogh."
的请求。该回答返回两个预测对象,每个对象都包含增强的提示和生成的图片字节(采用 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" } ] }