mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
feat: add PDF support and improve image handling in chat messages
This commit is contained in:
parent
b2232cda7b
commit
aaeaa24153
1 changed files with 9 additions and 4 deletions
|
@ -704,11 +704,12 @@ class Coder:
|
||||||
dict(role="assistant", content="Ok."),
|
dict(role="assistant", content="Ok."),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
dump(chat_files_messages)
|
||||||
return chat_files_messages
|
return chat_files_messages
|
||||||
|
|
||||||
def get_images_message(self):
|
def get_images_message(self):
|
||||||
if not self.main_model.info.get("supports_vision"):
|
#if not self.main_model.info.get("supports_vision"):
|
||||||
return None
|
# return None
|
||||||
|
|
||||||
image_messages = []
|
image_messages = []
|
||||||
for fname, content in self.get_abs_fnames_content():
|
for fname, content in self.get_abs_fnames_content():
|
||||||
|
@ -716,14 +717,18 @@ class Coder:
|
||||||
with open(fname, "rb") as image_file:
|
with open(fname, "rb") as image_file:
|
||||||
encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
|
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/"):
|
dump(mime_type)
|
||||||
|
if not mime_type:
|
||||||
|
continue
|
||||||
|
if mime_type.startswith("image/") or mime_type == "application/pdf":
|
||||||
image_url = f"data:{mime_type};base64,{encoded_string}"
|
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}"},
|
||||||
{"type": "image_url", "image_url": {"url": image_url, "detail": "high"}},
|
{"type": "image_url", "image_url": image_url},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
dump(image_messages)
|
||||||
if not image_messages:
|
if not image_messages:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue