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 2026-10-16 12:09:08 +02:00 • committed by GitHub
parent a5942da0a2
commit 823670d9fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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 ''