(feat) add support for gemini base64 images

This commit is contained in:
ishaan-jaff 2024-02-29 14:42:20 -08:00
parent 3d2150afcc
commit 8a96aa4ef0
3 changed files with 57 additions and 0 deletions

View file

@ -225,6 +225,17 @@ def _gemini_vision_convert_messages(messages: list):
part_mime = "video/mp4"
google_clooud_part = Part.from_uri(img, mime_type=part_mime)
processed_images.append(google_clooud_part)
elif "base64" in img:
# Case 4: Images with base64 encoding
import base64
# base 64 is passed as data:image/jpeg;base64,<base-64-encoded-image>
img_without_base_64 = img.split(",")[1]
decoded_img = base64.b64decode(img_without_base_64)
processed_image = Part.from_data(
data=decoded_img, mime_type="image/jpeg"
)
processed_images.append(processed_image)
return prompt, processed_images
except Exception as e:
raise e