Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
test(anthropic): narrow serialized image block before indexing
lei_leice9f767038b6
diff --git a/tests/ci/models/test_anthropic_data_url_case.py b/tests/ci/models/test_anthropic_data_url_case.pyindex e5b8208a4..290e7f25b 100644--- a/tests/ci/models/test_anthropic_data_url_case.py+++ b/tests/ci/models/test_anthropic_data_url_case.py@@ -1,4 +1,5 @@import pytest+from anthropic.types import ImageBlockParamfrom browser_use.llm.anthropic.serializer import AnthropicMessageSerializerfrom browser_use.llm.messages import ContentPartImageParam, ImageURL, UserMessage@@ -10,11 +11,16 @@ WEBP_DATA = 'UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA'HTTPS_URL = 'https://example.com/cat.png'-def serialize_image(url: str):+def serialize_image(url: str) -> ImageBlockParam:message = UserMessage(content=[ContentPartImageParam(image_url=ImageURL(url=url))])serialized = AnthropicMessageSerializer.serialize(message)- assert isinstance(serialized['content'], list)- return serialized['content'][0]+ content = serialized['content']+ assert isinstance(content, list)+ block = content[0]+ # Narrow the ContentBlockParam union down to an image block before indexing into it.+ assert isinstance(block, dict)+ assert block['type'] == 'image'+ return block@pytest.mark.parametrize(