fix: arXiv PDF links reach the model as raw bytes (#32524)

Files read from a URL are sent to a document parser based on their file name. An arXiv link like arxiv.org/pdf/1706.03762 has a dot in the paper ID, so the name was read as having the extension ".03762", the PDF went to the plain text reader and the model got raw PDF bytes. When the part after the dot is not a known file type, the extension now comes from the file type the server reports, so these links are read as PDFs. Files the server only labels as generic binary keep their name as before.
This commit is contained in:
Classic298 authored and GitHub committed 2026-10-16 14:09:08 +04:00
1 parent a5942da0a2
commit 823670d9fa
1 file changed
+3
+3
View File
@@ -120,6 +120,9 @@ def _extract_text_from_binary_response(
if not filename or '.' not in filename:
ext = mimetypes.guess_extension(content_type) or ''
filename = f'download{ext}'
elif not mimetypes.guess_type(filename)[0] and content_type != 'application/octet-stream':
# The dot in names like arXiv's 1706.03762 is not an extension.
filename += mimetypes.guess_extension(content_type) or ''
suffix = '.' + filename.split('.')[-1].lower() if '.' in filename else ''