diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 54c03593c..3903b296b 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -704,7 +704,6 @@ class Coder: dict(role="assistant", content="Ok."), ] - dump(chat_files_messages) return chat_files_messages def get_images_message(self): @@ -717,28 +716,26 @@ 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 not mime_type: continue + with open(fname, "rb") as image_file: + encoded_string = base64.b64encode(image_file.read()).decode("utf-8") + image_url = f"data:{mime_type};base64,{encoded_string}" + rel_fname = self.get_rel_fname(fname) + if mime_type.startswith("image/") and supports_images: - 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}"}, {"type": "image_url", "image_url": {"url": image_url, "detail": "high"}}, ] elif mime_type == "application/pdf" and supports_pdfs: - image_url = f"data:{mime_type};base64,{encoded_string}" - rel_fname = self.get_rel_fname(fname) image_messages += [ {"type": "text", "text": f"PDF file: {rel_fname}"}, {"type": "image_url", "image_url": image_url}, ] - dump(image_messages) if not image_messages: return None diff --git a/aider/models.py b/aider/models.py index 071c1fd6e..12e809c0f 100644 --- a/aider/models.py +++ b/aider/models.py @@ -17,7 +17,7 @@ from aider.dump import dump # noqa: F401 from aider.llm import litellm DEFAULT_MODEL_NAME = "gpt-4o" -ANTHROPIC_BETA_HEADER = "prompt-caching-2024-07-31" +ANTHROPIC_BETA_HEADER = "prompt-caching-2024-07-31,pdfs-2024-09-25" OPENAI_MODELS = """ gpt-4 diff --git a/aider/utils.py b/aider/utils.py index 4cf45b6dd..e91e5deb0 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -13,7 +13,7 @@ import git from aider.dump import dump # noqa: F401 -IMAGE_EXTENSIONS = {".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".webp"} +IMAGE_EXTENSIONS = {".png", ".jpg", ".jpeg", ".gif", ".bmp", ".tiff", ".webp", ".pdf"} class IgnorantTemporaryDirectory: