Skip to content

Commit 6b3d6ea

Browse files
zastrowmjsamuel1
authored andcommitted
feat: Add test that fails due to strands-agents#320 (strands-agents#322)
Co-authored-by: Mackenzie Zastrow <[email protected]>
1 parent 7130671 commit 6b3d6ea

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

tests-integ/test_model_openai.py

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
from pydantic import BaseModel
55

66
import strands
7-
from strands import Agent
7+
from strands import Agent, tool
8+
9+
if "OPENAI_API_KEY" not in os.environ:
10+
pytest.skip(allow_module_level=True, reason="OPENAI_API_KEY environment variable missing")
11+
812
from strands.models.openai import OpenAIModel
913

1014

@@ -36,21 +40,18 @@ def agent(model, tools):
3640
return Agent(model=model, tools=tools)
3741

3842

39-
@pytest.mark.skipif(
40-
"OPENAI_API_KEY" not in os.environ,
41-
reason="OPENAI_API_KEY environment variable missing",
42-
)
43+
@pytest.fixture
44+
def test_image_path(request):
45+
return request.config.rootpath / "tests-integ" / "test_image.png"
46+
47+
4348
def test_agent(agent):
4449
result = agent("What is the time and weather in New York?")
4550
text = result.message["content"][0]["text"].lower()
4651

4752
assert all(string in text for string in ["12:00", "sunny"])
4853

4954

50-
@pytest.mark.skipif(
51-
"OPENAI_API_KEY" not in os.environ,
52-
reason="OPENAI_API_KEY environment variable missing",
53-
)
5455
def test_structured_output(model):
5556
class Weather(BaseModel):
5657
"""Extracts the time and weather from the user's message with the exact strings."""
@@ -64,3 +65,31 @@ class Weather(BaseModel):
6465
assert isinstance(result, Weather)
6566
assert result.time == "12:00"
6667
assert result.weather == "sunny"
68+
69+
70+
@pytest.skip(
71+
reason="OpenAI provider cannot use tools that return images - https://github.com/strands-agents/sdk-python/issues/320"
72+
)
73+
def test_tool_returning_images(model, test_image_path):
74+
@tool
75+
def tool_with_image_return():
76+
with open(test_image_path, "rb") as image_file:
77+
encoded_image = image_file.read()
78+
79+
return {
80+
"status": "success",
81+
"content": [
82+
{
83+
"image": {
84+
"format": "png",
85+
"source": {"bytes": encoded_image},
86+
}
87+
},
88+
],
89+
}
90+
91+
agent = Agent(model=model, tools=[tool_with_image_return])
92+
# NOTE - this currently fails with: "Invalid 'messages[3]'. Image URLs are only allowed for messages with role
93+
# 'user', but this message with role 'tool' contains an image URL."
94+
# See https://github.com/strands-agents/sdk-python/issues/320 for additional details
95+
agent("Run the the tool and analyze the image")

0 commit comments

Comments
 (0)