Skip to content

Commit 4a5558f

Browse files
author
Evan Lin
committed
🔧 Update image handling in generate_vision_with_langchain to use binary data for improved compatibility with Vertex AI
1 parent c40a872 commit 4a5558f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

‎main.py‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,17 @@ def generate_vision_with_langchain(img, prompt):
136136
"""
137137
Generate a image vision result using LangChain with Vertex AI model.
138138
"""
139-
# Create a message with both text and image
139+
# Convert PIL Image to bytes
140+
img_byte_arr = BytesIO()
141+
img.save(img_byte_arr, format=img.format or 'JPEG')
142+
img_bytes = img_byte_arr.getvalue()
143+
144+
# Create a message with both text and image using proper Vertex AI format
140145
message = HumanMessage(
141146
content=[
142147
{"type": "text", "text": prompt},
143-
{"type": "image_url", "image_url": {"url": img}}
148+
# Use blob for binary data
149+
{"type": "image_url", "image_url": {"blob": img_bytes}}
144150
]
145151
)
146152

0 commit comments

Comments
 (0)