Skip to content
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
6 changes: 6 additions & 0 deletions pydantic_ai_slim/pydantic_ai/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'text/html',
'text/markdown',
'application/msword',
'application/vnd.ms-excel',
]
VideoMediaType: TypeAlias = Literal[
Expand Down Expand Up @@ -434,8 +435,12 @@ def _infer_media_type(self) -> str:
return 'application/pdf'
elif self.url.endswith('.rtf'):
return 'application/rtf'
elif self.url.endswith('.doc'):
return 'application/msword'
elif self.url.endswith('.docx'):
return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
elif self.url.endswith('.xls'):
return 'application/vnd.ms-excel'
elif self.url.endswith('.xlsx'):
return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'

Expand Down Expand Up @@ -645,6 +650,7 @@ class ToolReturn:
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
'text/html': 'html',
'text/markdown': 'md',
'application/msword': 'doc',
'application/vnd.ms-excel': 'xls',
}
_audio_format_lookup: dict[str, AudioFormat] = {
Expand Down
2 changes: 2 additions & 0 deletions tests/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ def test_binary_content_video(media_type: str, format: str):
('application/pdf', 'pdf'),
('text/plain', 'txt'),
('text/csv', 'csv'),
('application/msword', 'doc'),
('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'docx'),
('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'xlsx'),
('text/html', 'html'),
Expand Down Expand Up @@ -209,6 +210,7 @@ def test_image_url_invalid():
pytest.param(DocumentUrl('foobar.pdf'), 'application/pdf', 'pdf', id='pdf'),
pytest.param(DocumentUrl('foobar.txt'), 'text/plain', 'txt', id='txt'),
pytest.param(DocumentUrl('foobar.csv'), 'text/csv', 'csv', id='csv'),
pytest.param(DocumentUrl('foobar.doc'), 'application/msword', 'doc', id='doc'),
pytest.param(
DocumentUrl('foobar.docx'),
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
Expand Down