Merge branch 'main' into json-coders

This commit is contained in:
Paul Gauthier 2024-08-16 11:31:55 -07:00
commit d3e37c9e36
10 changed files with 425 additions and 355 deletions

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}"},