def __getitem__()

in src/open-r1-multimodal/src/open_r1/grpo_rec.py [0:0]


    def __getitem__(self, i):
        # Format into conversation
        def make_conversation(example):
            return {
                "prompt": [
                    {"role": "system", "content": SYSTEM_PROMPT},
                    {"role": "user", "content": example["problem"]},
                ],
            }
        # FIXME
        # This is only for Grounding task
        QUESTION_TEMPLATE = "{Question} First output the thinking process in <think> </think> tags and then output the final answer in <answer> </answer> tags. Output the final answer in JSON format."
        def make_conversation_image(example):
            return {
                "prompt": [
                    # {"role": "system", "content": [{"type": "text", "text": SYSTEM_PROMPT}]},
                    {
                        "role": "user",
                        "content": [
                            {"type": "image"},
                            {"type": "text", "text": QUESTION_TEMPLATE.format(Question=example["problem"])},
                        ],
                    },
                ],
            }

        has_image = 0
        example = self.list_data_dict[i]
        image_root = self.script_args.image_root
        if 'image' in example:
            if isinstance(example['image'], list):
                image_path = [os.path.join(image_root, x) for x in example['image']]
            else:
                image_path = [os.path.join(image_root, example['image'])]
            
            images = []
            for path in image_path:
                try:
                    image = Image.open(path).convert("RGB")
                    width, height = image.size
                    images.append(image)
                except Exception as e:
                    print("read image err: " + path)
                    continue
                if width < 50 or height < 50:
                    continue
            if len(images) == 0:
                images.append(Image.new('RGB', (224, 224), (255, 255, 255)))
            has_image = 1

            return {
                'has_image': has_image,
                'image': images,
                'problem': example['problem'],
                'solution': example['solution'],
                'prompt': make_conversation_image(example)['prompt']
            }
        
        return {
            'has_image': has_image,
            'problem': example['problem'],
            'solution': example['solution'],
            'prompt': make_conversation(example)['prompt'],
        }