MCPcopy
hub / github.com/Aider-AI/aider / get_images_message

Method get_images_message

aider/coders/base_coder.py:817–857  ·  view source on GitHub ↗
(self, fnames)

Source from the content-addressed store, hash-verified

815 return chat_files_messages
816
817 def get_images_message(self, fnames):
818 supports_images = self.main_model.info.get("supports_vision")
819 supports_pdfs = self.main_model.info.get("supports_pdf_input") or self.main_model.info.get(
820 "max_pdf_size_mb"
821 )
822
823 # https://github.com/BerriAI/litellm/pull/6928
824 supports_pdfs = supports_pdfs or "claude-3-5-sonnet-20241022" in self.main_model.name
825
826 if not (supports_images or supports_pdfs):
827 return None
828
829 image_messages = []
830 for fname in fnames:
831 if not is_image_file(fname):
832 continue
833
834 mime_type, _ = mimetypes.guess_type(fname)
835 if not mime_type:
836 continue
837
838 with open(fname, "rb") as image_file:
839 encoded_string = base64.b64encode(image_file.read()).decode("utf-8")
840 image_url = f"data:{mime_type};base64,{encoded_string}"
841 rel_fname = self.get_rel_fname(fname)
842
843 if mime_type.startswith("image/") and supports_images:
844 image_messages += [
845 {"type": "text", "text": f"Image file: {rel_fname}"},
846 {"type": "image_url", "image_url": {"url": image_url, "detail": "high"}},
847 ]
848 elif mime_type == "application/pdf" and supports_pdfs:
849 image_messages += [
850 {"type": "text", "text": f"PDF file: {rel_fname}"},
851 {"type": "image_url", "image_url": image_url},
852 ]
853
854 if not image_messages:
855 return None
856
857 return {"role": "user", "content": image_messages}
858
859 def run_stream(self, user_message):
860 self.io.user_input(user_message)

Callers 2

Calls 2

get_rel_fnameMethod · 0.95
is_image_fileFunction · 0.90

Tested by

no test coverage detected