VertexAIImageGenerator
此组件支持使用 Google Vertex AI 生成模型进行图像生成。
| 强制运行变量 | “prompt”: 包含模型提示的字符串 |
| 输出变量 | “images”: 一个包含模型生成的图像的 ByteStream 列表 |
| API 参考 | Google Vertex |
| GitHub 链接 | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/google_vertex |
VertexAIImageGenerator 支持imagegeneration 模型。
参数概述
VertexAIImageGenerator 使用 Google Cloud Application Default Credentials (ADCs) 进行身份验证。有关如何设置 ADCs 的更多信息,请参阅 官方文档。
请记住,使用有权访问已授权使用 Google Vertex AI 端点的项目的帐户至关重要。
您可以在GCP 资源管理器中找到您的项目 ID,或者通过在终端中运行gcloud projects list 来在本地找到。有关 gcloud CLI 的更多信息,请参阅其官方文档。
用法
您需要首先安装google-vertex-haystack 包以使用VertexAIImageGenerator:
pip install google-vertex-haystack
单独使用
基本用法
from pathlib import Path
from haystack_integrations.components.generators.google_vertex import VertexAIImageGenerator
generator = VertexAIImageGenerator()
result = generator.run(prompt="Generate an image of a cute cat")
result["images"][0].to_file(Path("my_image.png"))
您还可以设置其他参数,例如生成的图像数量和引导比例,以改变提示的强度。
我们还可以使用负面提示从图像中排除某些内容
from pathlib import Path
from haystack_integrations.components.generators.google_vertex import VertexAIImageGenerator
generator = VertexAIImageGenerator(
number_of_images=3,
guidance_scale=12,
)
result = generator.run(
prompt="Generate an image of a cute cat",
negative_prompt="window, chair",
)
for i, image in enumerate(result["images"]):
images.to_file(Path(f"image_{i}.png"))
更新于 大约 1 年前
