Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

feat: polish CLI help copy and add llama-cpp VLM server engine

jinzhenj2d786b1bdd61
diff --git a/mineru/cli/commands/cleanup.py b/mineru/cli/commands/cleanup.py
index 219bdfcb..1ceee845 100644
--- a/mineru/cli/commands/cleanup.py
+++ b/mineru/cli/commands/cleanup.py
@@ -19,7 +19,7 @@ from ..runtime import run_cli
app = typer.Typer(
name="cleanup",
- help=t("Clean up local doclib records and temp files."),
+ help=t("Clean up local document library records and temp files."),
no_args_is_help=True,
)
diff --git a/mineru/cli/commands/config.py b/mineru/cli/commands/config.py
index 59361535..5caec0fc 100644
--- a/mineru/cli/commands/config.py
+++ b/mineru/cli/commands/config.py
@@ -27,10 +27,10 @@ from ...utils.i18n import t
from ..contracts import CliContext
from ..runtime import run_cli
-app = typer.Typer(help=t("Configuration management"), no_args_is_help=True)
+app = typer.Typer(help=t("Show or override MinerU configuration values."), no_args_is_help=True)
-exclude_rules_app = typer.Typer(help=t("Exclude rule management"), no_args_is_help=True)
-parsing_rules_app = typer.Typer(help=t("Parsing rule management"), no_args_is_help=True)
+exclude_rules_app = typer.Typer(help=t("Manage rules that exclude files from the document library."), no_args_is_help=True)
+parsing_rules_app = typer.Typer(help=t("Manage parsing defaults applied to matching paths."), no_args_is_help=True)
app.add_typer(exclude_rules_app, name="exclude-rules")
app.add_typer(parsing_rules_app, name="parsing-rules")
@@ -103,7 +103,7 @@ def exclude_rules_remove(rule_id: int = typer.Argument(..., help=t("Rule id to r
def parsing_rules_add(
pattern: str = typer.Argument(..., help=t("Glob pattern to match")),
tier: Tier | None = typer.Option(None, "--tier", help=t("Parse tier: flash, basic, standard, advanced")),
- pages: str | None = typer.Option(None, "--pages", help=t("PDF pages, e.g. all, 1-10 or r3-r1")),
+ pages: str | None = typer.Option(None, "--pages", help=t("PDF pages, e.g. all, 1-10, or r3-r1 (counted from the end)")),
remote: bool = typer.Option(False, "--remote", help=t("Allow remote parsing")),
name: str | None = typer.Option(None, "--name", help=t("Rule name")),
json_mode: bool = typer.Option(False, "--json", help=t("JSON output")),
diff --git a/mineru/cli/commands/forget.py b/mineru/cli/commands/forget.py
index c30598ee..a09a9c18 100644
--- a/mineru/cli/commands/forget.py
+++ b/mineru/cli/commands/forget.py
@@ -13,7 +13,7 @@ from ..runtime import run_cli
def forget_cmd(
- path: str = typer.Argument(..., help=t("File or directory path to forget from doclib")),
+ path: str = typer.Argument(..., help=t("File or directory path to forget from the document library")),
dry_run: bool = typer.Option(True, "--dry-run/--no-dry-run", help=t("Preview only")),
json_mode: bool = typer.Option(False, "--json", help=t("JSON output")),
) -> None:
diff --git a/mineru/cli/commands/list_resources.py b/mineru/cli/commands/list_resources.py
index efbaaf25..f06f19ec 100644
--- a/mineru/cli/commands/list_resources.py
+++ b/mineru/cli/commands/list_resources.py
@@ -21,7 +21,7 @@ from ...utils.i18n import t
from ..contracts import CliContext
from ..runtime import run_cli
-app = typer.Typer(help=t("List doclib resources"), no_args_is_help=True)
+app = typer.Typer(help=t("List document library resources."), no_args_is_help=True)
@app.command("parses", help=t("List parse tasks."))
diff --git a/mineru/cli/commands/parse.py b/mineru/cli/commands/parse.py
index 370056db..dbfd7a7a 100644
--- a/mineru/cli/commands/parse.py
+++ b/mineru/cli/commands/parse.py
@@ -82,12 +82,17 @@ def parse_cmd(
"--tier",
help=t("Parse tier: flash, basic, standard, advanced (default: server decides)"),
),
- pages: str = typer.Option(None, "-p", "--pages", help=t("PDF pages: '1-5,8,r3-r1' or 'all'; default: first 10 pages")),
- after: str = typer.Option(None, "--after", help=t("Continue reading after a content cursor")),
- limit: int | None = typer.Option(None, "--limit", help=t("Soft character limit for STDOUT content")),
+ pages: str = typer.Option(
+ None,
+ "-p",
+ "--pages",
+ help=t("PDF pages: '1-5,8', 'r3-r1' (counted from the end), or 'all'; default: first 10 pages"),
+ ),
+ after: str = typer.Option(None, "--after", help=t("Continue reading after a content cursor from earlier output")),
+ limit: int | None = typer.Option(None, "--limit", help=t("Soft character limit for printed content")),
format: Literal["markdown"] = typer.Option("markdown", "-f", "--format", help=t("Output format: markdown")),
force: bool = typer.Option(False, "--force", help=t("Force re-parse, ignore cache")),
- remote: bool = typer.Option(False, "--remote", help=t("Use remote parse-server")),
+ remote: bool = typer.Option(False, "--remote", help=t("Use the mineru.net official remote parse service")),
wait: int = typer.Option(60, "--wait", help=t("Max seconds to wait for parse to complete")),
no_wait: bool = typer.Option(False, "--no-wait", help=t("Don't wait — return immediately")),
output: str = typer.Option(None, "-o", "--output", help=t("Output path; creates parent directories")),
diff --git a/mineru/cli/commands/read.py b/mineru/cli/commands/read.py
index 9bfc2d76..3b2b839f 100644
--- a/mineru/cli/commands/read.py
+++ b/mineru/cli/commands/read.py
@@ -24,9 +24,9 @@ class ReadTextOutput:
def read_cmd(
- locator: str = typer.Argument(..., help=t("Doclib locator, e.g. doc:ab12cd3/tier:basic/page:4")),
+ locator: str = typer.Argument(..., help=t("Document library locator, e.g. doc:ab12cd3/tier:basic/page:4")),
context: int = typer.Option(0, "--context", help=t("Read N pages/blocks before and after the locator")),
- limit: int = typer.Option(30000, "--limit", help=t("Soft character limit for STDOUT content")),
+ limit: int = typer.Option(30000, "--limit", help=t("Soft character limit for printed content")),
format: Literal["markdown", "image"] = typer.Option("markdown", "-f", "--format", help=t("Output format: markdown, image")),
output: str = typer.Option(None, "-o", "--output", help=t("Output path; creates parent directories")),
no_marker: bool = typer.Option(False, "--no-marker", help=t("Omit continuation marker from output")),
diff --git a/mineru/cli/commands/server.py b/mineru/cli/commands/server.py
index a70fc967..5f57f65b 100644
--- a/mineru/cli/commands/server.py
+++ b/mineru/cli/commands/server.py
@@ -27,7 +27,7 @@ from ...version import __version__
from ..contracts import CliContext, RenderableObject
from ..runtime import run_cli
-app = typer.Typer(help=t("Server lifecycle management"), no_args_is_help=True)
+app = typer.Typer(help=t("Start, stop, and inspect the local MinerU server."), no_args_is_help=True)
SERVER_START_TIMEOUT_SEC = 30.0
diff --git a/mineru/cli/commands/show.py b/mineru/cli/commands/show.py
index 6f933cde..e7632a4e 100644
--- a/mineru/cli/commands/show.py
+++ b/mineru/cli/commands/show.py
@@ -12,7 +12,7 @@ from ..contracts import CliContext
from ..path_utils import normalize_cli_path
from ..runtime import run_cli
-app = typer.Typer(help=t("Show doclib resource details"), no_args_is_help=True)
+app = typer.Typer(help=t("Show document library resource details."), no_args_is_help=True)
@app.command("parse", help=t("Show one parse task."))
diff --git a/mineru/cli/commands/telemetry.py b/mineru/cli/commands/telemetry.py
index 15629c23..2aac9b9e 100644
--- a/mineru/cli/commands/telemetry.py
+++ b/mineru/cli/commands/telemetry.py
@@ -13,7 +13,7 @@ from ...utils.i18n import t
from ..contracts import CliContext
from ..runtime import run_cli
-app = typer.Typer(help=t("Telemetry management"), no_args_is_help=True)
+app = typer.Typer(help=t("Manage anonymous usage telemetry."), no_args_is_help=True)
@app.command("status", help=t("Show telemetry status."))
diff --git a/mineru/cli/commands/usage.py b/mineru/cli/commands/usage.py
index 68b045e5..d1cd3f7a 100644
--- a/mineru/cli/commands/usage.py
+++ b/mineru/cli/commands/usage.py
@@ -52,7 +52,7 @@ def _get_remote_usage() -> RemoteUsageOutput:
def _render_remote_usage(view: RemoteUsageOutput) -> RenderableOutput:
usage = view.usage
lines = [
- t("Remote API Usage"),
+ t("Remote Parse Service Usage"),
"",
t("Remote URL: {url}", url=view.remote_url),
t("Access level: {level}", level=usage.access_level),
diff --git a/mineru/cli/commands/watch.py b/mineru/cli/commands/watch.py
index 6f49a0e3..4c028b26 100644
--- a/mineru/cli/commands/watch.py
+++ b/mineru/cli/commands/watch.py
@@ -14,7 +14,7 @@ from ..path_utils import normalize_cli_path
from ..runtime import cli_task, run_cli
from .scan import _render_scan, _wait_for_scan
-app = typer.Typer(help=t("Watch target management"), no_args_is_help=True)
+app = typer.Typer(help=t("Manage directories watched for automatic scanning."), no_args_is_help=True)
@app.command("add", help=t("Add a directory to watch."))
diff --git a/mineru/cli/guidance.py b/mineru/cli/guidance.py
index bcb385d4..db3af21e 100644
--- a/mineru/cli/guidance.py
+++ b/mineru/cli/guidance.py
@@ -63,7 +63,7 @@ def api_key_guidance_for_error(error: MineruError) -> CliGuidance | None:
if error.code == "invalid_api_key":
return _api_key_guidance(required=True, message=t("Configure a valid Official API Key to continue."))
if error.code == "feature_requires_api_key":
- return _api_key_guidance(required=True, message=t("This Remote API feature requires an Official API Key."))
+ return _api_key_guidance(required=True, message=t("This remote parse service feature requires an official API Key."))
if context.api_key_configured:
return None
if error.code == "rate_limit_exceeded":
diff --git a/mineru/cli/main.py b/mineru/cli/main.py
index f5758034..8b6b67e5 100644
--- a/mineru/cli/main.py
+++ b/mineru/cli/main.py
@@ -76,19 +76,19 @@ def root(
app.command("parse", help=t("Parse a document file."))(parse_cmd)
-app.command("read", help=t("Read parsed doclib content by locator."))(read_cmd)
-app.command("scan")(scan_cmd)
+app.command("read", help=t("Read parsed document content by locator."))(read_cmd)
+app.command("scan", help=t("Scan a file or directory into the document library."))(scan_cmd)
app.add_typer(watch.app, name="watch")
app.command("search", help=t("Search parsed document content."))(search_cmd)
app.command("find", help=t("Search filenames only (not document content)."))(find_cmd)
-app.command("usage", help=t("Show Remote API usage and limits."))(usage.usage_cmd)
+app.command("usage", help=t("Show remote parse service usage and limits."))(usage.usage_cmd)
app.add_typer(list_resources.app, name="list")
app.add_typer(show.app, name="show")
app.add_typer(telemetry.app, name="telemetry")
app.add_typer(server.app, name="server")
app.add_typer(config.app, name="config")
-app.command("invalidate", help=t("Mark done parse results as superseded."))(invalidate_cmd)
-app.command("forget")(forget_cmd)
+app.command("invalidate", help=t("Invalidate cached parse results so the next run parses again."))(invalidate_cmd)
+app.command("forget", help=t("Remove file records and cached results from the document library."))(forget_cmd)
app.add_typer(cleanup.app, name="cleanup")
app.command("version", help=t("Print MinerU and Python versions."))(version_cmd)
diff --git a/mineru/kit/commands/api_server.py b/mineru/kit/commands/api_server.py
index 32ee2bca..d442dbda 100644
--- a/mineru/kit/commands/api_server.py
+++ b/mineru/kit/commands/api_server.py
@@ -138,7 +138,7 @@ def main() -> None:
configure_standard_streams()
configure_global_log_level()
app = typer.Typer(add_completion=False)
- app.command(help=t("Forward explicit startup options and launch the self-hosted MinerU parsing API service."))(
+ app.command(help=t("Start the self-hosted MinerU parsing API service."))(
api_server_cmd
)
app()
diff --git a/mineru/kit/commands/parse.py b/mineru/kit/commands/parse.py
index 2fb6a1d4..9a5e63bc 100644
--- a/mineru/kit/commands/parse.py
+++ b/mineru/kit/commands/parse.py
@@ -29,7 +29,12 @@ from ..output import print_info, print_success
def parse_cmd(
inputs: list[str] = typer.Argument(..., help=t("Input files or directories")),
output: str = typer.Option(..., "-o", "--output", help=t("Output path; required")),
- pages: str | None = typer.Option(None, "-p", "--pages", help=t("PDF pages: '1-5,8,r3-r1' or 'all'; default: all pages")),
+ pages: str | None = typer.Option(
+ None,
+ "-p",
+ "--pages",
+ help=t("PDF pages: '1-5,8', 'r3-r1' (counted from the end), or 'all'; default: all pages"),
+ ),
format: str = typer.Option(
"markdown",
"-f",
diff --git a/mineru/kit/commands/vlm_server.py b/mineru/kit/commands/vlm_server.py
index 56c6327e..9b7955ab 100644
--- a/mineru/kit/commands/vlm_server.py
+++ b/mineru/kit/commands/vlm_server.py
@@ -68,31 +68,44 @@ def _run_with_forwarded_argv(main_fn: Callable[[], None], args: list[str]) -> No
sys.argv = original_argv
-def _resolve_auto_engine() -> Literal["vllm", "lmdeploy"]:
- """自动服务仅选择 vLLM 或 LMDeploy,MLX 必须显式指定。"""
+def _resolve_auto_engine() -> Literal["llama-cpp", "lmdeploy", "vllm"]:
+ """auto 优先 vLLM/LMDeploy(GPU 高吞吐),均不可用时回退 llama-cpp(base 依赖);MLX 必须显式指定。"""
if _module_available("vllm"):
logger.info(t("Using vLLM as the inference engine for VLM server."))
return "vllm"
if _module_available("lmdeploy"):
logger.info(t("Using LMDeploy as the inference engine for VLM server."))
return "lmdeploy"
- logger.info(t("No automatic VLM server engine is installed. Install vLLM/LMDeploy or explicitly choose --engine mlx."))
+ if _module_available("mineru_llama_cpp"):
+ logger.info(t("Using llama.cpp as the inference engine for VLM server."))
+ return "llama-cpp"
+ logger.info(
+ t("No VLM server engine is available. Install vLLM/LMDeploy/mineru-llama-cpp, or pass --engine explicitly.")
+ )
raise typer.Exit(1) from None
def vlm_server_cmd(
ctx: typer.Context,
- engine: str = typer.Option("auto", "--engine", help=t("VLM serving engine: auto, vllm, lmdeploy, mlx")),
+ engine: str = typer.Option("auto", "--engine", help=t("VLM serving engine: auto, llama-cpp, vllm, lmdeploy, mlx")),
) -> None:
"""Start the local VLM server with OpenAI-compatible chat completions."""
- if engine not in {"auto", "vllm", "lmdeploy", "mlx"}:
+ if engine not in {"auto", "llama-cpp", "vllm", "lmdeploy", "mlx"}:
exit_with_message("invalid_request", t("Unsupported engine '{engine}'.", engine=engine), "engine")
extra_args = list(ctx.args)
if engine == "auto":
engine = _resolve_auto_engine()
- if engine == "vllm":
+ if engine == "llama-cpp":
+ if not _module_available("mineru_llama_cpp"):
+ logger.error(t("mineru-llama-cpp is not installed. Install 'mineru-llama-cpp' to use the llama-cpp engine."))
+ raise typer.Exit(1) from None
+ from ..vlm_server import llama_cpp_server
+
+ _run_with_forwarded_argv(llama_cpp_server.main, extra_args)
+
+ elif engine == "vllm":
if not _module_available("vllm"):
logger.error(t("vLLM is not installed. Please install vLLM or choose lmdeploy/mlx as the engine."))
raise typer.Exit(1) from None
diff --git a/mineru/kit/main.py b/mineru/kit/main.py
index fcb5918e..57ebf608 100644
--- a/mineru/kit/main.py
+++ b/mineru/kit/main.py
@@ -32,7 +32,7 @@ class OrderedRootGroup(TyperGroup):
app = typer.Typer(
name="mineru-kit",
cls=OrderedRootGroup,
- help=t("MinerU Kit — parsing and service tools"),
+ help=t("MinerU Kit — batch parsing and service tools"),
no_args_is_help=True,
add_completion=False,
)
@@ -54,7 +54,7 @@ def root(
app.add_typer(models.app, name="models")
app.command("parse", help=t("Parse files or directories into markdown, middle JSON, or zip outputs."))(parse.parse_cmd)
app.command("webui", help=t("Start the Gradio document parsing web UI backed by the MinerU V1 API."))(webui.webui_cmd)
-app.command("api-server", help=t("Forward explicit startup options and launch the self-hosted MinerU parsing API service."))(
+app.command("api-server", help=t("Start the self-hosted MinerU parsing API service."))(
api_server.api_server_cmd
)
app.command(
diff --git a/mineru/kit/vlm_server/llama_cpp_server.py b/mineru/kit/vlm_server/llama_cpp_server.py
new file mode 100644
index 00000000..a6a5bba7
--- /dev/null
+++ b/mineru/kit/vlm_server/llama_cpp_server.py
@@ -0,0 +1,178 @@
+# Copyright (c) Opendatalab. All rights reserved.
+"""以薄包装启动 mineru-llama-cpp 分发的 llama-server(OpenAI 兼容)。
+
+llama-server 的全部服务能力由 llama.cpp 提供,本模块只补默认参数并以
+进程替换方式启动,llama.cpp 升级不需要改动这里。
+
+默认参数对齐 EngineCore::EngineCore(进程内 llama-cpp-engine)在 C++ 侧
+写死的 common_params 值,使 server 模式与解析模式的上下文容量、KV 分区、
+并发与日志行为保持一致;用户显式传入的参数逐项让位。
+"""
+
+from __future__ import annotations
+
+import os
+import struct
+import sys
+import typing
+from pathlib import Path
+
+from ...model.registry import vlm_model_repo
+
+DEFAULT_PORT = "30000"
+DEFAULT_N_GPU_LAYERS = 99
+DEFAULT_N_PARALLEL = 4
+# 日志级别不注入:保持 llama-server 自身默认(INFO),否则启动横幅里的
+# 监听地址/端口等关键信息会被 WARN 阈值压掉。
+# 与 mineru_llama_cpp.engine._VALID_UNICODE_GRAMMAR 同款:作为服务端默认 grammar,
+# 兜住 llama.cpp sampler 对 Q8_0 高分辨率页面可能采出的坏多字节 token;
+# 请求级 grammar 仍可覆盖服务端默认。
+VALID_UNICODE_GRAMMAR = "root ::= .*"
+
+_GGUF_MAGIC = b"GGUF"
+_GGUF_SCALAR_SIZE = {0: 1, 1: 1, 2: 2, 3: 2, 4: 4, 5: 4, 6: 4, 7: 1, 10: 8, 11: 8, 12: 8}
+_GGUF_STRING = 8
+_GGUF_ARRAY = 9
+_GGUF_UINT32 = 4
+
+
+def llama_server_binary() -> Path:
+ """定位 mineru-llama-cpp 包内分发的 llama-server 可执行文件。"""
+ import mineru_llama_cpp
+
+ return Path(mineru_llama_cpp.__file__).resolve().parent / "bin" / "llama-server"
+
+
+def _has_arg(args: list[str], *flags: str) -> bool:
+ return any(arg in flags or arg.startswith(f"{flag}=") for arg in args for flag in flags)
+
+
+def _flag_value(args: list[str], *flags: str) -> str | None:
+ for index, arg in enumerate(args):
+ for flag in flags:
+ if arg == flag and index + 1 < len(args):
+ return args[index + 1]
+ if arg.startswith(f"{flag}="):
+ return arg.split("=", 1)[1]
+ return None
+
+
+def _skip_gguf_value(f: typing.BinaryIO, value_type: int) -> None:
+ """按 gguf.h 的类型布局跳过一个 kv 值。"""
+ if value_type == _GGUF_STRING:
+ (length,) = struct.unpack("<Q", f.read(8))
+ f.seek(length, os.SEEK_CUR)
+ elif value_type == _GGUF_ARRAY:
+ (element_type,) = struct.unpack("<I", f.read(4))
+ (count,) = struct.unpack("<Q", f.read(8))
+ if element_type == _GGUF_STRING:
+ for _ in range(count):
+ (length,) = struct.unpack("<Q", f.read(8))
+ f.seek(length, os.SEEK_CUR)
+ else:
+ f.seek(count * _GGUF_SCALAR_SIZE.get(element_type, 0), os.SEEK_CUR)
+ else:
+ f.seek(_GGUF_SCALAR_SIZE.get(value_type, 0), os.SEEK_CUR)
+
+
+def _read_gguf_context_length(model_path: Path) -> int:
+ """读取 GGUF 的 `<architecture>.context_length`,失败返回 0。
+
+ 对齐 EngineCore 的 read_n_ctx_train_from_gguf:server 的 --ctx-size
+ 只接受总量,而进程内引擎按单 slot 训练上下文 × n_parallel 配 KV,
+ 所以这里必须自己从模型元数据取训练上下文。
+ """
+ try:
+ with model_path.open("rb") as f:
+ header = f.read(24)
+ if len(header) < 24 or header[:4] != _GGUF_MAGIC:
+ return 0
+ version, _tensor_count, kv_count = struct.unpack_from("<IQQ", header, 4)
+ if version < 2:
+ return 0
+ architecture = ""
+ for _ in range(kv_count):
+ (key_length,) = struct.unpack("<Q", f.read(8))
+ key = f.read(key_length).decode("utf-8", errors="replace")
+ (value_type,) = struct.unpack("<I", f.read(4))
+ if key == "general.architecture" and value_type == _GGUF_STRING:
+ (value_length,) = struct.unpack("<Q", f.read(8))
+ architecture = f.read(value_length).decode("utf-8", errors="replace")
+ continue
+ if architecture and key == f"{architecture}.context_length" and value_type == _GGUF_UINT32:
+ (value,) = struct.unpack("<I", f.read(4))
+ return int(value)
+ _skip_gguf_value(f, value_type)
+ except (OSError, struct.error):
+ return 0
+ return 0
+
+
+def main() -> None:
+ args = sys.argv[1:]
+
+ if not _has_arg(args, "--port"):
+ args.extend(["--port", DEFAULT_PORT])
+ if not _has_arg(args, "--grammar"):
+ args.extend(["--grammar", VALID_UNICODE_GRAMMAR])
+ # params_.special=true:MinerU 输出里的 <|box_start|> 等格式标记注册为
+ # special tokens,server 默认(false)会在输出 detokenize 时吞掉它们,
+ # 解析格式依赖这些标记,必须显式开启。
+ if not _has_arg(args, "--special"):
+ args.append("--special")
+
+ # 模型与 mmproj 必须成对来自同一模型;用户自定义任一参数时不再补默认,
+ # 避免拼出「自定义主模型 + 官方 mmproj」的不匹配组合。
+ model_path: Path | None = None
+ if _has_arg(args, "-m", "--model"):
+ value = _flag_value(args, "-m", "--model")
+ model_path = Path(value) if value else None
+ elif not _has_arg(args, "--mmproj"):
+ repo = vlm_model_repo("llama-cpp")
+ model_dir = repo.ensure()
+ model_path = model_dir / repo.paths["main"]
+ args.extend(["-m", str(model_path), "--mmproj", str(model_dir / repo.paths["mmproj"])])
+
+ # ---- 对齐 EngineCore::EngineCore 写死的 common_params(用户显式传入时逐项让位)----
+ user_defined_parallel = _has_arg(args, "--parallel")
+ user_defined_ctx = _has_arg(args, "-c", "--ctx-size")
+ if not user_defined_parallel:
+ args.extend(["--parallel", str(DEFAULT_N_PARALLEL)])
+ if not _has_arg(args, "-ngl", "--gpu-layers", "--n-gpu-layers"):
+ args.extend(["--n-gpu-layers", str(DEFAULT_N_GPU_LAYERS)])
+ # mmproj_use_gpu = (n_gpu_layers > 0):纯 CPU(ngl=0)时 mmproj 也不上 GPU;
+ # server 的 --mmproj-offload 默认无条件 enabled、不联动 ngl,需要显式对齐。
+ if not _has_arg(args, "--mmproj-offload", "--no-mmproj-offload"):
+ try:
+ mmproj_use_gpu = int(_flag_value(args, "-ngl", "--gpu-layers", "--n-gpu-layers") or DEFAULT_N_GPU_LAYERS) > 0
+ except ValueError:
+ mmproj_use_gpu = True
+ if not mmproj_use_gpu:
+ args.append("--no-mmproj-offload")
+ # EngineCore 用 kv_unified=false 的硬分区 KV(每 slot 私有 n_ctx_seq,互不侵占,
+ # 见 engine_core.cpp 的注释);llama-server 默认 unified=enabled,需显式关闭,
+ # 并同步关闭 idle-slot RAM 缓存(EngineCore 的 cache_idle_slots=false / cache_ram_mib=0)。
+ if not _has_arg(args, "--kv-unified", "--no-kv-unified"):
+ args.append("--no-kv-unified")
+ if not _has_arg(args, "--cache-ram", "-cram"):
+ args.extend(["--cache-ram", "0"])
+
+ # 总上下文 = n_ctx_seq(默认 0 → 训练上下文,读 GGUF) × n_parallel,复刻
+ # EngineCore 的 params_.n_ctx = n_ctx_seq * n_parallel;server 的 --ctx-size
+ # 是总量且默认 0 只含一份训练上下文,分区后每 slot 会缩水成 1/N。
+ # 用户自定义并发或上下文任一项时不再换算,容量交由用户决定。
+ if model_path is not None and not user_defined_ctx and not user_defined_parallel:
+ n_ctx_train = _read_gguf_context_length(model_path)
+ if n_ctx_train > 0:
+ args.extend(["--ctx-size", str(n_ctx_train * DEFAULT_N_PARALLEL)])
+
+ binary = llama_server_binary()
+ if not binary.is_file():
+ raise FileNotFoundError(f"llama-server binary not found: {binary}")
+
+ print(f"start llama.cpp server: {binary} {' '.join(args)}")
+ os.execv(str(binary), [str(binary), *args])
+
+
+if __name__ == "__main__":
+ main()
diff --git a/mineru/utils/translations.py b/mineru/utils/translations.py
index 488fd989..c3d7196f 100644
--- a/mineru/utils/translations.py
+++ b/mineru/utils/translations.py
@@ -18,10 +18,12 @@ ZH_MESSAGES: dict[str, str] = {
"no": "否",
"Error:": "错误:",
"Output path; creates parent directories": "输出路径;自动创建父目录",
- "Soft character limit for STDOUT content": "STDOUT 内容的软字符上限",
+ "Soft character limit for printed content": "输出内容的软字符上限",
"File not found: {path}": "文件不存在: {path}",
"File or directory not found: {path}": "文件或目录不存在: {path}",
"Show the version and exit.": "显示版本并退出。",
+ "Scan a file or directory into the document library.": "把文件或目录扫描进文档库。",
+ "Remove file records and cached results from the document library.": "从文档库移除文件记录与缓存结果。",
"Print MinerU and Python versions.": "显示 MinerU 与 Python 版本。",
"MinerU version: {version}": "MinerU 版本: {version}",
"Python version: {version}": "Python 版本: {version}",
@@ -32,21 +34,23 @@ ZH_MESSAGES: dict[str, str] = {
# ------------------------------------------------------------- mineru 根
"MinerU — your personal document center, built for agents": "MinerU — 你的个人文档中心,为 agent 而建",
"Parse a document file.": "解析一个文档文件。",
- "Read parsed doclib content by locator.": "按定位符读取已解析的 doclib 内容。",
+ "Read parsed document content by locator.": "按定位符读取已解析的文档内容。",
"Search parsed document content.": "搜索已解析的文档内容。",
"Search filenames only (not document content).": "仅搜索文件名(不搜索文档内容)。",
- "Show Remote API usage and limits.": "显示 Remote API 用量与限额。",
- "Mark done parse results as superseded.": "将已完成的解析结果标记为已作废。",
+ "Show remote parse service usage and limits.": "显示远程解析服务的用量与限额。",
+ "Invalidate cached parse results so the next run parses again.": "使缓存的解析结果失效,下次运行时重新解析。",
# ----------------------------------------------------------------- parse
"Path to the document file": "文档文件路径",
"Parse tier: flash, basic, standard, advanced (default: server decides)": (
"解析档位: flash、basic、standard、advanced(默认由服务端决定)"
),
- "PDF pages: '1-5,8,r3-r1' or 'all'; default: first 10 pages": "PDF 页码: '1-5,8,r3-r1' 或 'all';默认前 10 页",
- "Continue reading after a content cursor": "从内容游标之后继续读取",
+ "PDF pages: '1-5,8', 'r3-r1' (counted from the end), or 'all'; default: first 10 pages": (
+ "PDF 页码: '1-5,8'、'r3-r1'(倒数页码)或 'all';默认前 10 页"
+ ),
+ "Continue reading after a content cursor from earlier output": "从早前输出中的内容游标之后继续读取",
"Output format: markdown": "输出格式: markdown",
"Force re-parse, ignore cache": "强制重新解析,忽略缓存",
- "Use remote parse-server": "使用远程 parse-server",
+ "Use the mineru.net official remote parse service": "使用 mineru.net 官方远程解析服务",
"Max seconds to wait for parse to complete": "等待解析完成的最长秒数",
"Don't wait — return immediately": "不等待,立即返回",
"Omit document structure markers from output": "输出中省略文档结构标记",
@@ -64,7 +68,7 @@ ZH_MESSAGES: dict[str, str] = {
"Parse IDs": "解析任务 ID",
"{label}: {ids}": "{label}: {ids}",
# ------------------------------------------------------------------ read
- "Doclib locator, e.g. doc:ab12cd3/tier:basic/page:4": "doclib 定位符,如 doc:ab12cd3/tier:basic/page:4",
+ "Document library locator, e.g. doc:ab12cd3/tier:basic/page:4": "文档库定位符,如 doc:ab12cd3/tier:basic/page:4",
"Read N pages/blocks before and after the locator": "在定位符前后各读取 N 页/块",
"Output format: markdown, image": "输出格式: markdown、image",
"Omit continuation marker from output": "输出中省略续读标记",
@@ -83,7 +87,7 @@ ZH_MESSAGES: dict[str, str] = {
"unreachable={unreachable}, excluded={excluded}, unsupported={unsupported}"
),
# ----------------------------------------------------------------- watch
- "Watch target management": "监视目标管理",
+ "Manage directories watched for automatic scanning.": "管理自动扫描的监视目录。",
"Add a directory to watch.": "添加要监视的目录。",
"List watched directories.": "列出被监视的目录。",
"Remove a watched directory.": "移除一个被监视的目录。",
@@ -120,7 +124,7 @@ ZH_MESSAGES: dict[str, str] = {
"Files:": "文件:",
"File no longer exists.": "文件已不存在。",
# ----------------------------------------------------------------- usage
- "Remote API Usage": "Remote API 用量",
+ "Remote Parse Service Usage": "远程解析服务用量",
"Remote URL: {url}": "Remote URL: {url}",
"Access level: {level}": "访问级别: {level}",
"Billing period: {period}": "计费周期: {period}",
@@ -139,7 +143,7 @@ ZH_MESSAGES: dict[str, str] = {
"{days} day": "{days} 天",
"{days} days": "{days} 天",
# ------------------------------------------------------------------ list
- "List doclib resources": "列出 doclib 资源",
+ "List document library resources.": "列出文档库资源。",
"List parse tasks.": "列出解析任务。",
"List scan tasks.": "列出扫描任务。",
"List file path records.": "列出文件路径记录。",
@@ -171,7 +175,7 @@ ZH_MESSAGES: dict[str, str] = {
"Type": "类型",
"Title": "标题",
# ------------------------------------------------------------------ show
- "Show doclib resource details": "显示 doclib 资源详情",
+ "Show document library resource details.": "显示文档库资源详情。",
"Show one parse task.": "显示单个解析任务。",
"Show one scan task.": "显示单个扫描任务。",
"Show file, doc, and parse state for a local path.": "显示某个本地路径的文件、文档与解析状态。",
@@ -204,7 +208,7 @@ ZH_MESSAGES: dict[str, str] = {
"Image based": "是否图片型",
"Files": "文件",
# -------------------------------------------------------- telemetry 命令
- "Telemetry management": "遥测管理",
+ "Manage anonymous usage telemetry.": "管理匿名使用遥测。",
"Show telemetry status.": "显示遥测状态。",
"Print the next telemetry request body without sending it.": "打印下一次遥测请求体,但不发送。",
"Enable telemetry.": "启用遥测。",
@@ -221,7 +225,7 @@ ZH_MESSAGES: dict[str, str] = {
"telemetry flush: {reason}": "遥测已上报: {reason}",
"telemetry {state}": "遥测 {state}",
# ---------------------------------------------------------------- server
- "Server lifecycle management": "服务生命周期管理",
+ "Start, stop, and inspect the local MinerU server.": "启动、停止和查看本地 MinerU 服务。",
"Start the mineru server in the background.": "在后台启动 mineru 服务。",
"Stop the mineru server gracefully.": "优雅停止 mineru 服务。",
"Restart the mineru server.": "重启 mineru 服务。",
@@ -309,9 +313,9 @@ ZH_MESSAGES: dict[str, str] = {
"{age}h ago": "{age} 小时前",
"{age}d ago": "{age} 天前",
# ---------------------------------------------------------------- config
- "Configuration management": "配置管理",
- "Exclude rule management": "排除规则管理",
- "Parsing rule management": "解析规则管理",
+ "Show or override MinerU configuration values.": "查看或覆盖 MinerU 配置值。",
+ "Manage rules that exclude files from the document library.": "管理将文件排除在文档库之外的规则。",
+ "Manage parsing defaults applied to matching paths.": "管理应用到匹配路径的解析默认值。",
"Show effective configuration values.": "显示生效的配置值。",
"Show one effective configuration value.": "显示单个生效配置值。",
"Set a configuration override.": "设置一个配置覆盖。",
@@ -339,7 +343,7 @@ ZH_MESSAGES: dict[str, str] = {
"Exclude rule {rule_id} removed.": "排除规则 {rule_id} 已移除。",
"Exclude rule {rule_id} unchanged.": "排除规则 {rule_id} 无变化。",
"Glob pattern to match": "要匹配的 glob 模式",
- "PDF pages, e.g. all, 1-10 or r3-r1": "PDF 页码,如 all、1-10 或 r3-r1",
+ "PDF pages, e.g. all, 1-10, or r3-r1 (counted from the end)": "PDF 页码,如 all、1-10 或 r3-r1(倒数页码)",
"Allow remote parsing": "允许远程解析",
"Rule name": "规则名称",
"Add a parsing rule.": "添加一条解析规则。",
@@ -352,7 +356,7 @@ ZH_MESSAGES: dict[str, str] = {
"Parsing rule {rule_id} removed.": "解析规则 {rule_id} 已移除。",
"Parsing rule {rule_id} unchanged.": "解析规则 {rule_id} 无变化。",
# --------------------------------------------------------------- cleanup
- "Clean up local doclib records and temp files.": "清理本地 doclib 记录与临时文件。",
+ "Clean up local document library records and temp files.": "清理本地文档库记录与临时文件。",
"Preview only": "仅预览",
"Days threshold for temp cleanup": "临时文件清理的天数阈值",
"Remove all file rows already marked as deleted.": "移除所有已标记为删除的文件记录。",
@@ -366,7 +370,7 @@ ZH_MESSAGES: dict[str, str] = {
"Removed {count} orphan doc(s).": "已移除 {count} 个孤儿文档。",
"Removed {count} temp file(s).": "已移除 {count} 个临时文件。",
# ---------------------------------------------------------------- forget
- "File or directory path to forget from doclib": "要从 doclib 移除记录的文件或目录路径",
+ "File or directory path to forget from the document library": "要从文档库移除记录的文件或目录路径",
"Would forget {count} file record(s) (matched_as={matched_as}). Use --no-dry-run to proceed.": (
"将移除 {count} 条文件记录(matched_as={matched_as})。加 --no-dry-run 执行。"
),
@@ -384,7 +388,7 @@ ZH_MESSAGES: dict[str, str] = {
"MinerU server is busy. Retry the request.": "MinerU 服务繁忙。请重试请求。",
# -------------------------------------------------------------- guidance
"Configure a valid Official API Key to continue.": "请配置有效的官方 API Key 后继续。",
- "This Remote API feature requires an Official API Key.": "此 Remote API 功能需要官方 API Key。",
+ "This remote parse service feature requires an official API Key.": "此远程解析服务功能需要官方 API Key。",
"An Official API Key is optional and may provide registered rate limits.": (
"官方 API Key 为可选项,配置后可获得注册用户的速率限制。"
),
@@ -423,13 +427,13 @@ ZH_MESSAGES: dict[str, str] = {
),
"Enable telemetry?": "启用遥测?",
# ------------------------------------------------------------- kit 根
- "MinerU Kit — parsing and service tools": "MinerU Kit — 解析与服务工具",
+ "MinerU Kit — batch parsing and service tools": "MinerU Kit — 批量解析与服务工具",
"Parse files or directories into markdown, middle JSON, or zip outputs.": (
"将文件或目录解析为 markdown、middle JSON 或 zip 输出。"
),
"Start the Gradio document parsing web UI backed by the MinerU V1 API.": "启动基于 MinerU V1 API 的 Gradio 文档解析界面。",
- "Forward explicit startup options and launch the self-hosted MinerU parsing API service.": (
- "转发显式启动参数,启动 self-hosted MinerU 解析 API 服务。"
+ "Start the self-hosted MinerU parsing API service.": (
+ "启动自托管的 MinerU 解析 API 服务。"
),
"Start the local VLM server with OpenAI-compatible chat completions.": (
"启动本地 VLM 服务,提供 OpenAI 兼容的 chat completions。"
@@ -438,7 +442,9 @@ ZH_MESSAGES: dict[str, str] = {
# ------------------------------------------------------------ kit parse
"Input files or directories": "输入文件或目录",
"Output path; required": "输出路径;必填",
- "PDF pages: '1-5,8,r3-r1' or 'all'; default: all pages": "PDF 页码: '1-5,8,r3-r1' 或 'all';默认全部页面",
+ "PDF pages: '1-5,8', 'r3-r1' (counted from the end), or 'all'; default: all pages": (
+ "PDF 页码: '1-5,8'、'r3-r1'(倒数页码)或 'all';默认全部页面"
+ ),
"Output format: markdown, middle_json, zip": "输出格式: markdown、middle_json、zip",
"Use mineru.net official remote parse service": "使用 mineru.net 官方远程解析服务",
"Use a custom remote parse service URL": "使用自定义远程解析服务 URL",
@@ -505,12 +511,16 @@ ZH_MESSAGES: dict[str, str] = {
"API 服务日志级别: critical、error、warning、info、debug、trace;默认取全局 log.level。同时过滤 Loguru 默认模型日志 sink"
),
# ------------------------------------------------------- kit vlm-server
- "VLM serving engine: auto, vllm, lmdeploy, mlx": "VLM 推理服务引擎: auto、vllm、lmdeploy、mlx",
+ "VLM serving engine: auto, llama-cpp, vllm, lmdeploy, mlx": "VLM 推理服务引擎: auto、llama-cpp、vllm、lmdeploy、mlx",
"Unsupported engine '{engine}'.": "不支持的引擎 '{engine}'。",
+ "mineru-llama-cpp is not installed. Install 'mineru-llama-cpp' to use the llama-cpp engine.": (
+ "未安装 mineru-llama-cpp,请安装 'mineru-llama-cpp' 以使用 llama-cpp 引擎。"
+ ),
"Using vLLM as the inference engine for VLM server.": "使用 vLLM 作为 VLM 服务的推理引擎。",
"Using LMDeploy as the inference engine for VLM server.": "使用 LMDeploy 作为 VLM 服务的推理引擎。",
- "No automatic VLM server engine is installed. Install vLLM/LMDeploy or explicitly choose --engine mlx.": (
- "未安装可自动选择的 VLM 服务引擎。请安装 vLLM/LMDeploy,或显式指定 --engine mlx。"
+ "Using llama.cpp as the inference engine for VLM server.": "使用 llama.cpp 作为 VLM 服务的推理引擎。",
+ "No VLM server engine is available. Install vLLM/LMDeploy/mineru-llama-cpp, or pass --engine explicitly.": (
+ "没有可用的 VLM 服务引擎。请安装 vLLM/LMDeploy/mineru-llama-cpp,或显式指定 --engine。"
),
"vLLM is not installed. Please install vLLM or choose lmdeploy/mlx as the engine.": (
"未安装 vLLM。请安装 vLLM,或选择 lmdeploy/mlx 作为引擎。"