VertexAIImageQA
VertexAIImageQA
Google Vertex AI의 생성 모델을 사용해 이미지에 대한 질문에 답하는 텍스트(이미지 캡셔닝)를 생성하는 컴포넌트예요. 이미지와 질문을 주면 모델이 답을 만들어 줘요.
필수 run 변수: image — 이미지 데이터를 담은 ByteStream / question — 이미지에 대한 질문 문자열
출력 변수: replies — 모델이 생성한 답변을 담은 문자열 리스트
API 레퍼런스: Google Vertex
GitHub 링크: https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/google_vertex
패키지 이름: google-vertex-haystack
VertexAIImageQA는 imagetext 모델을 지원해요.
출처: 문서
본문
파라미터 개요 (Parameters Overview)
VertexAIImageQA는 인증에 Google Cloud Application Default Credentials (ADC)를 사용해요. ADC 설정 방법은 공식 문서를 참고하세요.
Google Vertex AI 엔드포인트를 사용하도록 승인된 프로젝트에 접근 권한이 있는 계정을 쓰는 게 중요하다는 점을 기억하세요.
프로젝트 ID는 GCP 리소스 매니저에서 찾거나, 터미널에서 gcloud projects list를 실행해 찾을 수 있어요. gcloud CLI에 대한 자세한 내용은 공식 문서를 참고하세요.
사용법 (Usage)
VertexAIImageQA를 쓰려면 google-vertex-haystack 패키지를 설치해야 해요:
pip install google-vertex-haystack
단독으로 사용하기 (On its own)
기본 사용법:
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