feat: add progress_callback support for real-time conversion tracking#1851
Open
echavet wants to merge 2 commits into
Open
feat: add progress_callback support for real-time conversion tracking#1851echavet wants to merge 2 commits into
echavet wants to merge 2 commits into
Conversation
Add ConversionProgress dataclass and ProgressCallback Protocol to enable real-time progress reporting during document conversion. Converters emit progress events for each logical unit processed: - PdfConverter: per page - PptxConverter: per slide - EpubConverter: per chapter - XlsxConverter / XlsConverter: per sheet The callback is optional and passed via kwargs (progress_callback). Converters that do not support progress simply ignore it. Fully backward-compatible — no changes to existing API signatures. Signed-off-by: Eric Chavet <echavet@gmail.com>
Author
|
@microsoft-github-policy-service agree |
When llm_client and llm_model are provided, PdfConverter now rasterises pages that contain no extractable text (scans, screenshots) and sends them to the vision LLM for a structured Markdown description. Uses pdfplumber's page.to_image() (Pillow-backed, 150 DPI) to render each empty page as PNG, then calls the OpenAI-compatible chat API with the image as a base64 data-URI. This complements the existing progress_callback feature and does not affect PDF pages that have extractable text.
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.
Summary
Adds a
progress_callbackmechanism to MarkItDown converters, enabling callers to receive real-time progress updates during document conversion.Problem Solved
When converting large documents (e.g. a 213-page PDF),
convert()blocks for several minutes with no way to report progress to the user. Server-side applications, worker processes, and UIs cannot display meaningful feedback during long conversions.Design
Two new public types in
_base_converter.py:ConversionProgress— a frozen@dataclasscarryingcurrent,total,unit(page/slide/chapter/sheet), andsource(converter class name).ProgressCallback— a@runtime_checkableProtocolthat any callable matching(ConversionProgress) -> Nonesatisfies (structural subtyping / duck typing).The callback is passed through the existing
**kwargschain (convert()→_convert()→converter.convert()). Converters that do not support progress simply ignore the kwarg.Converters Updated
PdfConverterpagePptxConverterslideEpubConverterchapterXlsxConvertersheetXlsConvertersheetUsage Example
Backward Compatibility
graphrag-inputand other consumers work without modificationType of Change
Testing
ConversionProgressdataclass andProgressCallbackProtocol validated at runtime