Skip to content

fix(cli): allow Document Intelligence conversion from stdin - #2455

Open
Leo Camus (Dev-next-gen) wants to merge 1 commit into
microsoft:mainfrom
Dev-next-gen:fix/cli-docintel-stdin
Open

fix(cli): allow Document Intelligence conversion from stdin#2455
Leo Camus (Dev-next-gen) wants to merge 1 commit into
microsoft:mainfrom
Dev-next-gen:fix/cli-docintel-stdin

Conversation

@Dev-next-gen

Copy link
Copy Markdown

While reading #2318, which let --use-cu read its input from stdin, I noticed the --use-docintel branch just above it still stops with "Filename is required when using Document Intelligence." whenever no filename is given. markitdown -d -e <endpoint> doc.pdf works, markitdown --use-cu --cu-endpoint <endpoint> < doc.pdf works, but markitdown -d -e <endpoint> < doc.pdf exits with status 1 before converting anything.

Nothing in DocumentIntelligenceConverter needs a path. convert() reads file_stream and sends the bytes as bytes_source, and accepts() only looks at the extension and MIME type, which stdin mode already gets from -x/-m or from magika. So I removed the check the same way #2318 did for Content Understanding.

The new tests/test_cli_docintel.py runs main() with a PDF on stdin and the Azure client mocked. It checks that the stdin bytes are what reaches AnalyzeDocumentRequest and that the markdown returned by the service is printed. On main it fails with SystemExit: 1 and 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 it DocumentIntelligenceConverter.convert is called with extension .pdf and 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

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant