Skip to content

Commit 59faf42

Browse files
Add support for detecting and handling application/msword files. (#3318)
Co-authored-by: Douwe Maan <[email protected]>
1 parent d16f634 commit 59faf42

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pydantic_ai_slim/pydantic_ai/messages.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
3535
'text/html',
3636
'text/markdown',
37+
'application/msword',
3738
'application/vnd.ms-excel',
3839
]
3940
VideoMediaType: TypeAlias = Literal[
@@ -434,8 +435,12 @@ def _infer_media_type(self) -> str:
434435
return 'application/pdf'
435436
elif self.url.endswith('.rtf'):
436437
return 'application/rtf'
438+
elif self.url.endswith('.doc'):
439+
return 'application/msword'
437440
elif self.url.endswith('.docx'):
438441
return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'
442+
elif self.url.endswith('.xls'):
443+
return 'application/vnd.ms-excel'
439444
elif self.url.endswith('.xlsx'):
440445
return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
441446

@@ -645,6 +650,7 @@ class ToolReturn:
645650
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': 'xlsx',
646651
'text/html': 'html',
647652
'text/markdown': 'md',
653+
'application/msword': 'doc',
648654
'application/vnd.ms-excel': 'xls',
649655
}
650656
_audio_format_lookup: dict[str, AudioFormat] = {

tests/test_messages.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ def test_binary_content_video(media_type: str, format: str):
147147
('application/pdf', 'pdf'),
148148
('text/plain', 'txt'),
149149
('text/csv', 'csv'),
150+
('application/msword', 'doc'),
150151
('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'docx'),
151152
('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'xlsx'),
152153
('text/html', 'html'),
@@ -209,6 +210,7 @@ def test_image_url_invalid():
209210
pytest.param(DocumentUrl('foobar.pdf'), 'application/pdf', 'pdf', id='pdf'),
210211
pytest.param(DocumentUrl('foobar.txt'), 'text/plain', 'txt', id='txt'),
211212
pytest.param(DocumentUrl('foobar.csv'), 'text/csv', 'csv', id='csv'),
213+
pytest.param(DocumentUrl('foobar.doc'), 'application/msword', 'doc', id='doc'),
212214
pytest.param(
213215
DocumentUrl('foobar.docx'),
214216
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',

0 commit comments

Comments
 (0)