DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.
Python ai-agentsai-tutorclawbotcli-tooldeepresearchinteractive-learninglearningmulti-agent-systemsrag
"""MinerU engine adapter implementing the ``Parser`` protocol.
The readiness gate (``readiness.py``) enforces "no silent model download"
before a local parse runs.
"""
from __future__ import annotations
from pathlib import Path
from typing import Callable, Optional
from ...base import ReadinessReport
from ...signature import ParserSignature
from .._versions import package_version
from .config import MinerUConfig, resolve_mineru_config
from .formats import MINERU_SUPPORTED_FORMATS
from .readiness import mineru_readiness
class MinerUParser:
"""Documents/images → multimodal IR via the MinerU CLI or cloud API."""
name = "mineru"
needs_local_models = True
@classmethod
def is_available(cls) -> bool:
# MinerU is an external CLI (local) or hosted API (cloud); the adapter
# has no hard Python import. It is always "available" — readiness gates
# whether a parse can actually run.
return True
def resolve_config(self) -> MinerUConfig:
return resolve_mineru_config()
def supported_formats(self) -> frozenset[str]:
return MINERU_SUPPORTED_FORMATS
def signature(self, config: MinerUConfig) -> ParserSignature:
from .normalization import POLICY
version = f"cloud:{config.api_base_url}" if config.is_cloud else package_version("mineru")
return ParserSignature.build(
"mineru",
version,
{
"mode": config.mode,
"model_version": config.model_version,
"language": config.language,
"enable_formula": config.enable_formula,
"enable_table": config.enable_table,
"is_ocr": config.is_ocr,
**(
{
"segmentation": "source-pages-v1",
"max_pages_per_part": config.max_pages_per_part,
}
if config.is_cloud
else {}
),
**(
{"normalization": POLICY}
if config.is_cloud and config.normalize_tiny_scans
else {}
),
},
)
def is_ready(self, config: MinerUConfig) -> ReadinessReport:
return mineru_readiness(config)
def parse(
self,
source_path: Path,
workdir: Path,
*,
config: MinerUConfig,
on_output: Optional[Callable[[str], None]] = None,
) -> None:
from .backend import parse_document_to_workdir
# Writes ``<workdir>/<stem>/...`` (markdown + content_list + images);
# ParseService loads the IR from ``workdir`` afterwards.
parse_document_to_workdir(source_path, workdir, config=config, on_output=on_output)
__all__ = ["MinerUParser"]