fix(cli): allow Document Intelligence conversion from stdin - #2455
Open
Leo Camus (Dev-next-gen) wants to merge 1 commit into
Open
fix(cli): allow Document Intelligence conversion from stdin#2455Leo Camus (Dev-next-gen) wants to merge 1 commit into
Leo Camus (Dev-next-gen) wants to merge 1 commit into
Conversation
The --use-docintel branch still exited with "Filename is required when using Document Intelligence." when no filename was given, although DocumentIntelligenceConverter only reads the stream's bytes. microsoft#2318 removed the same check for --use-cu; drop it here too so stdin works for both.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While reading #2318, which let
--use-curead its input from stdin, I noticed the--use-docintelbranch just above it still stops with "Filename is required when using Document Intelligence." whenever no filename is given.markitdown -d -e <endpoint> doc.pdfworks,markitdown --use-cu --cu-endpoint <endpoint> < doc.pdfworks, butmarkitdown -d -e <endpoint> < doc.pdfexits with status 1 before converting anything.Nothing in
DocumentIntelligenceConverterneeds a path.convert()readsfile_streamand sends the bytes asbytes_source, andaccepts()only looks at the extension and MIME type, which stdin mode already gets from-x/-mor from magika. So I removed the check the same way #2318 did for Content Understanding.The new
tests/test_cli_docintel.pyrunsmain()with a PDF on stdin and the Azure client mocked. It checks that the stdin bytes are what reachesAnalyzeDocumentRequestand that the markdown returned by the service is printed. On main it fails withSystemExit: 1and the "Filename is required" message. With the change it passes. I also ran the real CLI against an unreachable endpoint: before the change stdin exits on the filename check, after itDocumentIntelligenceConverter.convertis called with extension.pdfand the output is identical to passing the same file by path.The full suite passes locally (761 passed, 14 skipped, Linux, Python 3.12), and black 23.7.0 leaves both files unchanged.
AI tools used