文档API 参考📓 教程🧑‍🍳 食谱🤝 集成💜 Discord🎨 Studio
文档

VertexAIImageQA

此组件支持使用 Google Vertex AI 生成模型进行文本生成(图像字幕)。

强制运行变量“image”:一个包含图像数据的 ByteStream

“question”:一个关于图像的问题字符串
输出变量“replies”:一个包含模型生成答案的字符串列表
API 参考Google Vertex
GitHub 链接https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/google_vertex

VertexAIImageQA 支持imagetext 模型。

参数概述

VertexAIImageQA 使用 Google Cloud 应用程序默认凭据 (ADC) 进行身份验证。有关如何设置 ADC 的更多信息,请参阅 官方文档

请记住,使用有权访问已授权使用 Google Vertex AI 端点的项目的帐户至关重要。

您可以在GCP 资源管理器中找到您的项目 ID,或者通过在终端中运行gcloud projects list 来在本地找到。有关 gcloud CLI 的更多信息,请参阅其官方文档

用法

您需要首先安装google-vertex-haystack 包以使用VertexAIImageQA:

pip install google-vertex-haystack

单独使用

基本用法

from haystack.dataclasses.byte_stream import ByteStream
from haystack_integrations.components.generators.google_vertex import VertexAIImageQA


qa = VertexAIImageQA()

image = ByteStream.from_file_path("dog.jpg")

res = qa.run(image=image, question="What color is this dog")

print(res["replies"][0])

>>> white

您还可以设置生成的答案数量

from haystack.dataclasses.byte_stream import ByteStream
from haystack_integrations.components.generators.google_vertex import VertexAIImageQA


qa = VertexAIImageQA(
    number_of_results=3,
)
image = ByteStream.from_file_path("dog.jpg")

res = qa.run(image=image, question="Tell me something about this dog")

for answer in res["replies"]:
    print(answer)

>>> pomeranian
>>> white
>>> pomeranian puppy

相关链接

请查看 GitHub 仓库或我们的文档中的 API 参考