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
feiyu169
commented
Jul 24, 2026
feiyu169
left a comment
Author
There was a problem hiding this comment.
Hermes Agent Code Review
整体评价:这是一个高质量的 PR,架构清晰、测试充分、文档完善。五层回退链设计合理,统一中间格式 ConvertedDocument 解耦了后端差异。
✅ 正确性
- 五层回退链逻辑清晰:云 API 单次 → 分批 → CLI → Python API → Docling
- 配额检查放在 COS 上传之后,避免白扣(设计文档中提到的 v4.1 修复)
_poll_one的指数退避 + jitter 实现正确_flatten_content_list正确处理了嵌套结构和未知 block type
✅ 安全性
_try_parse_with_mineru_cli使用shell=False+ 列表形式调用 subprocess,无注入风险- COS 凭证通过环境变量注入,未硬编码
- 临时文件在
try/finally中清理
✅ 代码质量
document_protocol.py使用 frozen dataclass,数据不可变- 异常层次分明:
MinerUAPIError→MinerUTimeoutError/MinerUTaskFailedError docling_export.py的 fallback 函数签名设计优雅:(payload_dict, suffix)元组
✅ 测试
- 306 行基础测试 + 773 行运行时测试,覆盖核心逻辑
- 已有 9 个测试文件适配新接口签名
- 4281 测试通过,pyright 0 errors
💡 建议(非阻塞)
dayu/mineru_runtime.py—_prefetch_zip_urls函数有import zipfile但未使用,且该函数当前未被调用。如果是 P2 优化预留,建议添加 TODO 注释说明。dayu/cos_helper.py— COS 凭证在模块级加载(_COS_SECRET_ID = os.environ.get(...)),进程启动后环境变量变更不会生效。建议文档中注明需重启进程。dayu/mineru_runtime.py:_submit_task—is_ocr=True,enable_formula=True,language="ch"等参数硬编码。如果未来需要支持英文文档或其他配置,建议从pdf_backend.py的 config 函数读取。
Author
PR Review 总结仓库: 📊 概览
✅ 通过项
💡 建议(非阻塞)
结论: 代码质量高,无需阻塞合并。建议项可在后续 PR 中处理。 Reviewed by Hermes Agent (automated) |
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)环境变量
测试结果