feat(mineru): MinerU v4.1 — Cloud API + Docling Fallback + Kuaishou 374p Verified#161
Open
feiyu169 wants to merge 2 commits into
Open
feat(mineru): MinerU v4.1 — Cloud API + Docling Fallback + Kuaishou 374p Verified#161feiyu169 wants to merge 2 commits into
feiyu169 wants to merge 2 commits into
Conversation
…74p Verified Core (5 new modules, +1719 lines): - dayu/document_protocol.py: ConvertedDocument unified format + bbox version detection - dayu/mineru_runtime.py: MinerU cloud API v4 (COS + concurrent polling + zip + 5-layer fallback) - dayu/quota_tracker.py: Persistent quota tracker (5000 pages/day) - dayu/cos_helper.py: Tencent COS upload/delete helper - dayu/config/pdf_backend.py: MinerU config module Pipeline (2 modified): - dayu/fins/docling_export.py: +convert_pdf_bytes_with_fallback (Docling-first, MinerU fallback) - dayu/fins/pipelines/docling_upload_service.py: Fallback integration, stores _mineru.json Tests (2 new, 9 adapted): - tests/test_mineru_basic.py: 30 tests - tests/test_mineru_runtime.py: 26 tests - 9 existing test files adapted for new signatures v4.1 key fixes: - Quota check moved after COS upload (avoid false deduction) - _KNOWN_BLOCK_TYPES: added paragraph/image - COS filename parameterized (was hardcoded kuaishou2025.pdf) - Fallback stores _mineru.json only (no redundant .md) E2E verified: kuaishou 2025 annual report 374 pages → 78.7s 2398 sections, 202 tables, 112 images, 341KB markdown 4281 tests passed, pyright 0 errors GBrain: mineru-integration-plan-v4.1 Docs: docs/mineru-v4.1-changelog.md
Author
|
添加了MinerU的支持,对中文的财报适配更加优秀 |
层4 Python API (magic_pdf.tools.common.do_parse):
- try/except Exception 包裹,模型下载异常不穿透
- tempfile 临时文件 + try/finally 清理
层3 CLI (magic-pdf subprocess):
- 修复 shutil.which("mineru") → "magic-pdf"
- subprocess.run shell=False,timeout=300
- try/except Exception 包裹
代码重构:
- 抽取 _flatten_content_list + _build_document_from_blocks 消除 4 处重复
- 抽取 _cleanup_temp_files 统一层3/层4 清理逻辑
- 提取 4 个命名常量消除魔法数字
测试:
- 层3 CLI: 9 个 mock 测试 + 1 个 skip-if-not-installed 烟雾测试
- 层4 Python API: 8 个 mock 测试 + 1 个 skip-if-not-installed 烟雾测试
- MineruProcessor: 31 个单元测试覆盖全部 7 个接口
- 总计: 66 passed, 0 failed, pyright 0 errors
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.
概述
MinerU 云 API v4 集成到 dayu-agent,作为 PDF 解析后端。当 Docling 解析失败(港股复杂 PDF 超时/崩溃)时,自动 fallback 到 MinerU 云 API。
核心收益:快手 2025 年报(374 页 / 9.9MB 港股 PDF)解析耗时从 Docling CPU >10min(未完成)降低到 MinerU 云 API 78.7s。
新增文件(5 个模块 + 2 个测试 + 1 个文档)
dayu/document_protocol.pyConvertedDocument(frozen dataclass)+ bbox 版本探测dayu/mineru_runtime.pydayu/quota_tracker.pydayu/cos_helper.pydayu/config/pdf_backend.pytests/test_mineru_basic.pytests/test_mineru_runtime.pydocs/mineru-v4.1-changelog.md修改文件
dayu/fins/docling_export.pyconvert_pdf_bytes_with_fallback:Docling 优先,失败 fallback 到 MinerUdayu/fins/pipelines/docling_upload_service.py_mineru.jsonpyproject.toml五层回退链
v4.1 关键修复
_mineru.json(不存冗余.md)环境变量
测试结果