def _prepare_messages(
        self, messages: Sequence[ChatMessage], image_documents: Sequence[ImageDocument]
    ) -> Dict[str, Any]:
        """
        Prepares the input messages and images for Qwen2 models. Images are appended in a custom format.
        """
        conversation = []
        for img_doc in image_documents:
            conversation.append(
                {"type": "image", "image": img_doc.image_path}
            )  # Append images to conversation
        conversation.append(
            {"type": "text", "text": messages[0].content}
        )  # Add user text message

        messages = [
            {"role": "user", "content": conversation}
        ]  # Wrap conversation in a user role

        # Apply a chat template to format the message with the processor
        text_prompt = self._processor.tokenizer.apply_chat_template(
            messages, tokenize=False, add_generation_prompt=True
        )
        image_inputs, _ = process_vision_info(messages)

        # Prepare the model inputs (text + images) and convert to tensor
        inputs = self._processor(
            text=[text_prompt], images=image_inputs, padding=True, return_tensors="pt"
        )
        return inputs.to(self.device)

        Prepares the input messages and images for Qwen2 models. Images are appended in a custom format.
        
llama-index-integrations/multi_modal_llms/llama-index-multi-modal-llms-huggingface/llama_index/multi_modal_llms/huggingface/base.py