(match)
| 557 | self.logger.info(f"Found {len(matches)} image path matches in prompt") |
| 558 | |
| 559 | def replace_image_path(match): |
| 560 | nonlocal images_processed |
| 561 | |
| 562 | image_path = match.group(1).strip() |
| 563 | self.logger.debug(f"Processing image path: '{image_path}'") |
| 564 | |
| 565 | # Validate path format (basic check) |
| 566 | if not image_path or len(image_path) < 3: |
| 567 | self.logger.warning(f"Invalid image path format: {image_path}") |
| 568 | return match.group(0) # Keep original |
| 569 | |
| 570 | # Use utility function to validate image file |
| 571 | self.logger.debug(f"Calling validate_image_file for: {image_path}") |
| 572 | is_valid = validate_image_file(image_path) |
| 573 | self.logger.debug(f"Validation result for {image_path}: {is_valid}") |
| 574 | |
| 575 | if not is_valid: |
| 576 | self.logger.warning(f"Image validation failed for: {image_path}") |
| 577 | return match.group(0) # Keep original if validation fails |
| 578 | |
| 579 | try: |
| 580 | # Encode image to base64 using utility function |
| 581 | self.logger.debug(f"Attempting to encode image: {image_path}") |
| 582 | image_base64 = encode_image_to_base64(image_path) |
| 583 | if image_base64: |
| 584 | images_processed += 1 |
| 585 | # Save base64 to instance variable for later use |
| 586 | self._current_images_base64.append(image_base64) |
| 587 | |
| 588 | # Keep original path info and add VLM marker |
| 589 | result = f"Image Path: {image_path}\n[VLM_IMAGE_{images_processed}]" |
| 590 | self.logger.debug( |
| 591 | f"Successfully processed image {images_processed}: {image_path}" |
| 592 | ) |
| 593 | return result |
| 594 | else: |
| 595 | self.logger.error(f"Failed to encode image: {image_path}") |
| 596 | return match.group(0) # Keep original if encoding failed |
| 597 | |
| 598 | except Exception as e: |
| 599 | self.logger.error(f"Failed to process image {image_path}: {e}") |
| 600 | return match.group(0) # Keep original |
| 601 | |
| 602 | # Execute replacement |
| 603 | enhanced_prompt = re.sub( |
nothing calls this directly
no test coverage detected