Skip to content
Open
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
223 changes: 162 additions & 61 deletions pydantic_ai_slim/pydantic_ai/messages.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pydantic_ai_slim/pydantic_ai/models/bedrock.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ async def _map_user_prompt( # noqa: C901
name = f'Document {next(document_count)}'
document: DocumentBlockTypeDef = {
'name': name,
'format': item.format,
'format': item.format, # type: ignore[assignment]
'source': source,
}
content.append({'document': document})
Expand Down
3 changes: 3 additions & 0 deletions pydantic_ai_slim/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ dbos = ["dbos>=1.14.0"]
# Prefect
prefect = ["prefect>=3.4.21"]

magika = ["magika>=1.0.1"]
magic = ["python-magic>=0.4.27"]

[tool.hatch.metadata]
allow-direct-references = true

Expand Down
23 changes: 20 additions & 3 deletions tests/models/test_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -3149,7 +3149,9 @@ async def test_google_image_generation(allow_model_requests: None, google_provid
result = await agent.run('Generate an image of an axolotl.')
messages = result.all_messages()

assert result.output == snapshot(BinaryImage(data=IsBytes(), media_type='image/jpeg', _identifier='b6e95a'))
assert result.output == snapshot(
BinaryImage(data=IsBytes(), media_type='image/jpeg', _media_type='image/jpeg', _identifier='b6e95a')
)
assert messages == snapshot(
[
ModelRequest(
Expand All @@ -3167,6 +3169,7 @@ async def test_google_image_generation(allow_model_requests: None, google_provid
content=BinaryImage(
data=IsBytes(),
media_type='image/jpeg',
_media_type='image/jpeg',
_identifier='b6e95a',
),
provider_details={'thought_signature': IsStr()},
Expand All @@ -3190,7 +3193,9 @@ async def test_google_image_generation(allow_model_requests: None, google_provid
)

result = await agent.run('Now give it a sombrero.', message_history=messages)
assert result.output == snapshot(BinaryImage(data=IsBytes(), media_type='image/jpeg', _identifier='14bec0'))
assert result.output == snapshot(
BinaryImage(data=IsBytes(), media_type='image/jpeg', _media_type='image/jpeg', _identifier='14bec0')
)
assert result.new_messages() == snapshot(
[
ModelRequest(
Expand All @@ -3208,6 +3213,7 @@ async def test_google_image_generation(allow_model_requests: None, google_provid
content=BinaryImage(
data=IsBytes(),
media_type='image/jpeg',
_media_type='image/jpeg',
_identifier='14bec0',
),
provider_details={'thought_signature': IsStr()},
Expand Down Expand Up @@ -3245,6 +3251,7 @@ async def test_google_image_generation_stream(allow_model_requests: None, google
BinaryImage(
data=IsBytes(),
media_type='image/png',
_media_type='image/png',
_identifier='9ff9cc',
identifier='9ff9cc',
)
Expand All @@ -3263,6 +3270,7 @@ async def test_google_image_generation_stream(allow_model_requests: None, google
BinaryImage(
data=IsBytes(),
media_type='image/png',
_media_type='image/png',
_identifier='2af2a7',
identifier='2af2a7',
)
Expand All @@ -3285,6 +3293,7 @@ async def test_google_image_generation_stream(allow_model_requests: None, google
content=BinaryImage(
data=IsBytes(),
media_type='image/png',
_media_type='image/png',
_identifier='2af2a7',
identifier='2af2a7',
)
Expand Down Expand Up @@ -3317,6 +3326,7 @@ async def test_google_image_generation_stream(allow_model_requests: None, google
content=BinaryImage(
data=IsBytes(),
media_type='image/png',
_media_type='image/png',
_identifier='2af2a7',
)
),
Expand Down Expand Up @@ -3364,6 +3374,7 @@ async def test_google_image_generation_with_text(allow_model_requests: None, goo
content=BinaryImage(
data=IsBytes(),
media_type='image/jpeg',
_media_type='image/jpeg',
_identifier='00f2af',
identifier=IsStr(),
),
Expand Down Expand Up @@ -3403,6 +3414,7 @@ async def test_google_image_or_text_output(allow_model_requests: None, google_pr
BinaryImage(
data=IsBytes(),
media_type='image/png',
_media_type='image/png',
_identifier='f82faf',
identifier='f82faf',
)
Expand All @@ -3422,6 +3434,7 @@ async def test_google_image_and_text_output(allow_model_requests: None, google_p
BinaryImage(
data=IsBytes(),
media_type='image/png',
_media_type='image/png',
_identifier='67b12f',
identifier='67b12f',
)
Expand Down Expand Up @@ -3474,6 +3487,7 @@ class Animal(BaseModel):
content=BinaryImage(
data=IsBytes(),
media_type='image/jpeg',
_media_type='image/jpeg',
_identifier='4e5b3e',
),
provider_details={'thought_signature': IsStr()},
Expand Down Expand Up @@ -3566,7 +3580,9 @@ async def test_google_image_generation_with_web_search(allow_model_requests: Non
result = await agent.run(
'Visualize the current weather forecast for the next 5 days in Mexico City as a clean, modern weather chart. Add a visual on what I should wear each day'
)
assert result.output == snapshot(BinaryImage(data=IsBytes(), media_type='image/jpeg', _identifier='787c28'))
assert result.output == snapshot(
BinaryImage(data=IsBytes(), media_type='image/jpeg', _media_type='image/jpeg', _identifier='787c28')
)
assert result.all_messages() == snapshot(
[
ModelRequest(
Expand Down Expand Up @@ -3613,6 +3629,7 @@ async def test_google_image_generation_with_web_search(allow_model_requests: Non
content=BinaryImage(
data=IsBytes(),
media_type='image/jpeg',
_media_type='image/jpeg',
_identifier='787c28',
),
provider_details={'thought_signature': IsStr()},
Expand Down
9 changes: 7 additions & 2 deletions tests/models/test_mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -2044,7 +2044,7 @@ async def test_image_as_binary_content_input(allow_model_requests: None):
UserPromptPart(
content=[
'hello',
BinaryContent(data=image_bytes, media_type='image/jpeg'),
BinaryContent(data=image_bytes, _media_type='image/jpeg', media_type='image/jpeg'),
],
timestamp=IsDatetime(),
)
Expand Down Expand Up @@ -2128,7 +2128,12 @@ async def test_pdf_as_binary_content_input(allow_model_requests: None):
UserPromptPart(
content=[
'hello',
BinaryContent(data=base64_content, media_type='application/pdf', identifier='b9d976'),
BinaryContent(
data=base64_content,
_media_type='application/pdf',
media_type='application/pdf',
identifier='b9d976',
),
],
timestamp=IsDatetime(),
)
Expand Down
Loading
Loading