Skip to content

Commit 5e47596

Browse files
committed
Added 2 tests to cover Images with Magic Classes
1 parent a576aae commit 5e47596

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

tests/models/test_magic_parts.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,21 @@ async def test_openai_video_url_raises_not_implemented():
171171

172172
with pytest.raises(NotImplementedError):
173173
await OpenAIChatModel._map_single_item(VideoUrl(url='https://example.com/file.mp4'))
174+
175+
176+
async def test_openai_image_url_maps_to_image_url_part():
177+
# Functional: verify that an ImageUrl input maps to an image_url content part
178+
from pydantic_ai.messages import ImageUrl
179+
180+
part = UserPromptPart(content=[ImageUrl(url='https://example.com/picture.png')])
181+
msg = await OpenAIChatModel._map_user_prompt(part)
182+
content = cast(list[dict[str, Any]], msg['content'])
183+
assert content[0]['type'] == 'image_url'
184+
185+
186+
async def test_openai_magic_binary_image_maps_to_image_url():
187+
# Functional: MagicBinaryContent with image/* should map to image_url content part
188+
part = UserPromptPart(content=[MagicBinaryContent(data=b'\x89PNG', media_type='image/png')])
189+
msg = await OpenAIChatModel._map_user_prompt(part)
190+
content = cast(list[dict[str, Any]], msg['content'])
191+
assert content[0]['type'] == 'image_url'

0 commit comments

Comments
 (0)