mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00
fix: Use base64 to encode images in get_images_message
This commit is contained in:
parent
36a8ed6eed
commit
e6bf5d8f48
1 changed files with 4 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import base64
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import locale
|
import locale
|
||||||
|
@ -652,9 +653,11 @@ class Coder:
|
||||||
image_messages = []
|
image_messages = []
|
||||||
for fname, content in self.get_abs_fnames_content():
|
for fname, content in self.get_abs_fnames_content():
|
||||||
if is_image_file(fname):
|
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)
|
mime_type, _ = mimetypes.guess_type(fname)
|
||||||
if mime_type and mime_type.startswith("image/"):
|
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)
|
rel_fname = self.get_rel_fname(fname)
|
||||||
image_messages += [
|
image_messages += [
|
||||||
{"type": "text", "text": f"Image file: {rel_fname}"},
|
{"type": "text", "text": f"Image file: {rel_fname}"},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue