Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Vision Capability Test for MacOS #2260

Merged
merged 5 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions test/agentchat/contrib/capabilities/test_vision_capability.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ def lmm_config():
}


def png_filename() -> str:
filename = "tmp/test_image.png"
if not os.path.exists(filename):
# Setup: Create a PNG file
image = Image.new("RGB", (100, 100), color="blue")
image.save(filename)
return filename # This is what the test will use
img_name = os.path.abspath("test/test_files/test_image.png")


@pytest.fixture
Expand Down Expand Up @@ -84,9 +78,9 @@ def test_process_last_received_message_text(mock_lmm_client, vision_capability):
def test_process_last_received_message_with_image(
mock_get_caption, mock_convert_base64, mock_get_image_data, vision_capability
):
content = [{"type": "image_url", "image_url": {"url": (png_filename())}}]
content = [{"type": "image_url", "image_url": {"url": (img_name)}}]
expected_caption = (
f"<img {png_filename()}> in case you can not see, the caption of this image is: A sample image caption.\n"
f"<img {img_name}> in case you can not see, the caption of this image is: A sample image caption.\n"
)
processed_content = vision_capability.process_last_received_message(content)
assert processed_content == expected_caption
Expand All @@ -113,15 +107,15 @@ def caption_func(image_url: str, image_data=None, lmm_client=None) -> str:
class TestCustomCaptionFunc:
def test_custom_caption_func_with_valid_url(self, custom_caption_func):
"""Test custom caption function with a valid image URL."""
image_url = png_filename()
image_url = img_name
expected_caption = f"An image description. The image is from {image_url}."
assert custom_caption_func(image_url) == expected_caption, "Caption does not match expected output."

def test_process_last_received_message_with_custom_func(self, lmm_config, custom_caption_func):
"""Test processing a message containing an image URL with a custom caption function."""
vision_capability = VisionCapability(lmm_config, custom_caption_func=custom_caption_func)

image_url = png_filename()
image_url = img_name
content = [{"type": "image_url", "image_url": {"url": image_url}}]
expected_output = f" An image description. The image is from {image_url}."
processed_content = vision_capability.process_last_received_message(content)
Expand Down
Binary file added test/test_files/test_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading