Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
feat: add effort parameter validation and backend options for hybrid parsing
myhloliad587d3dfc5c
diff --git a/mineru/cli_old/api_request.py b/mineru/cli_old/api_request.pyindex 913118d4..af350a9b 100644--- a/mineru/cli_old/api_request.py+++ b/mineru/cli_old/api_request.py@@ -5,6 +5,14 @@ from typing import Annotated, Optionalfrom fastapi import File, Form, HTTPException, Request, UploadFilefrom mineru.cli_old.public_http_client_policy import validate_public_http_client_request+from mineru.utils.backend_options import (+ BACKEND_SCHEMA_EXTRA,+ DEFAULT_BACKEND,+ DEFAULT_HYBRID_EFFORT,+ HYBRID_EFFORT_SCHEMA_EXTRA,+ normalize_public_backend,+ validate_effort,+)ALLOWED_PARSE_METHODS = {"auto", "txt", "ocr"}SWAGGER_UI_FILE_ARRAY_SCHEMA_EXTRA = {@@ -21,6 +29,7 @@ class ParseRequestOptions:files: list[UploadFile]lang_list: list[str]backend: str+ effort: strparse_method: strformula_enable: booltable_enable: bool@@ -51,6 +60,22 @@ def validate_parse_method(parse_method: str) -> str:return parse_method+def validate_parse_backend(backend: str) -> str:+ """校验公开 API 允许的解析后端,避免旧入口名进入下游执行链路。"""+ try:+ return normalize_public_backend(backend)+ except ValueError as exc:+ raise HTTPException(status_code=400, detail=str(exc)) from exc+++def validate_parse_effort(effort: str) -> str:+ """校验公开 API 允许的 hybrid effort,避免非法值进入解析链路。"""+ try:+ return validate_effort(effort)+ except ValueError as exc:+ raise HTTPException(status_code=400, detail=str(exc)) from exc++async def parse_request_form(request: Request,files: Annotated[@@ -63,7 +88,7 @@ async def parse_request_form(lang_list: Annotated[list[str],Form(- description="""(Adapted only for pipeline and hybrid backend)Input the languages in the pdf to improve OCR accuracy.Options:+ description="""(Adapted for pipeline backend only) Input the languages in the pdf to improve OCR accuracy. Options:- ch: Chinese, English, Chinese Traditional.- ch_lite: Chinese, English, Chinese Traditional, Japanese.- ch_server: Chinese, English, Chinese Traditional, Japanese.@@ -89,12 +114,22 @@ async def parse_request_form(Form(description="""The backend for parsing:- pipeline: More general, supports multiple languages, hallucination-free.-- vlm-auto-engine: High accuracy via local computing power, supports Chinese and English documents only.+- vlm-engine: High accuracy via local computing power, supports Chinese and English documents only.- vlm-http-client: High accuracy via remote computing power(client suitable for openai-compatible servers), supports Chinese and English documents only.-- hybrid-auto-engine: Next-generation high accuracy solution via local computing power, supports multiple languages.-- hybrid-http-client: High accuracy via remote computing power but requires a little local computing power(client suitable for openai-compatible servers), supports multiple languages.""",+- hybrid-engine: Hybrid parsing via local computing power, supports multiple languages. Use effort to switch medium/high behavior.+- hybrid-http-client: Hybrid parsing via remote computing power but requires a little local computing power(client suitable for openai-compatible servers), supports multiple languages. Use effort to switch medium/high behavior.""",+ json_schema_extra=BACKEND_SCHEMA_EXTRA,),- ] = "hybrid-auto-engine",+ ] = DEFAULT_BACKEND,+ effort: Annotated[+ str,+ Form(+ description="""(Adapted only for hybrid backend) Hybrid parsing effort:+- medium: Faster parsing for most documents, balancing accuracy and efficiency. Image/chart analysis is disabled.+- high: Higher-accuracy parsing with image/chart analysis support, which may take longer.""",+ json_schema_extra=HYBRID_EFFORT_SCHEMA_EXTRA,+ ),+ ] = DEFAULT_HYBRID_EFFORT,parse_method: Annotated[str,Form(@@ -115,7 +150,12 @@ async def parse_request_form(] = True,image_analysis: Annotated[bool,- Form(description="Enable image/chart analysis for VLM and hybrid backends."),+ Form(+ description=(+ "Enable image/chart analysis for VLM and hybrid backends. "+ "Hybrid medium effort automatically disables image/chart analysis."+ ),+ ),] = True,server_url: Annotated[Optional[str],@@ -175,6 +215,8 @@ async def parse_request_form(] = 99999,) -> ParseRequestOptions:"""解析 API/Router 共用的 multipart 表单,并保持 Swagger 参数同源。"""+ backend = validate_parse_backend(backend)+ effort = validate_parse_effort(effort)validate_public_http_client_request(public_bind_exposed=bool(getattr(request.app.state, "public_bind_exposed", False)@@ -197,6 +239,7 @@ async def parse_request_form(files=files,lang_list=lang_list,backend=backend,+ effort=effort,parse_method=validate_parse_method(parse_method),formula_enable=formula_enable,table_enable=table_enable,diff --git a/mineru/utils/backend_options.py b/mineru/utils/backend_options.pyindex b9b8e5e0..9dcc398a 100644--- a/mineru/utils/backend_options.py+++ b/mineru/utils/backend_options.py@@ -21,6 +21,8 @@ HTTP_CLIENT_BACKEND_CHOICES: Final[tuple[str, ...]] = ()PUBLIC_BACKEND_CHOICES: Final[tuple[str, ...]] = LOCAL_BACKEND_CHOICES + HTTP_CLIENT_BACKEND_CHOICESHYBRID_EFFORT_CHOICES: Final[tuple[str, ...]] = ("medium", "high")+BACKEND_SCHEMA_EXTRA: Final[dict[str, list[str]]] = {"enum": list(PUBLIC_BACKEND_CHOICES)}+HYBRID_EFFORT_SCHEMA_EXTRA: Final[dict[str, list[str]]] = {"enum": list(HYBRID_EFFORT_CHOICES)}BACKEND_ALIASES: Final[dict[str, str]] = {"vlm-auto-engine": CANONICAL_VLM_ENGINE,