fix: Use base64 to encode images in get_images_message

This commit is contained in:
Paul Gauthier (aider) 2024-08-15 14:09:31 -07:00
parent 36a8ed6eed
commit e6bf5d8f48

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python
import base64
import hashlib
import json
import locale
@ -652,9 +653,11 @@ class Coder:
image_messages = []
for fname, content in self.get_abs_fnames_content():
if is_image_file(fname):
with open(fname, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
mime_type, _ = mimetypes.guess_type(fname)
if mime_type and mime_type.startswith("image/"):
image_url = f"data:{mime_type};base64,{content}"
image_url = f"data:{mime_type};base64,{encoded_string}"
rel_fname = self.get_rel_fname(fname)
image_messages += [
{"type": "text", "text": f"Image file: {rel_fname}"},