dsh-pdf-zh: A DSH Plugin for Translating English Research PDFs into Chinese

Introduction

The philosophy behind DeepSeek Harness (DSH) is “everything is a plugin.” In research, reading English-language papers is a daily necessity; constantly switching between a PDF viewer and a browser tab for translation is costly. Existing solutions either rely on online translation services or destroy the original layout; running a local translation model, on the other hand, requires you to pick a model, configure GPU memory, and tune parameters yourself. The dsh-pdf-zh plugin described below ties all three concerns together: built on DSH’s plugin system, it calls PDFMathTranslate (via pdf2zh) to preserve the original layout, recommends a suitable local translation model based on your GPU’s VRAM, and provides a translation routing layer that supports local, DeepSeek, and free API backends.

What It Is

dsh-pdf-zh is a DeepSeek Harness plugin maintained by honghufox. Its core goal is to translate English research PDFs into Chinese while preserving the original PDF layout (formulas, figures, two-column typesetting) and producing a citable bilingual Markdown draft. The plugin also provides GPU-aware local model recommendations and a built-in routing system across local, DeepSeek, and free API translation backends.

Core Features

The plugin registers three tools:

  • pdf_translate: Set to: pdf to get a bilingual or monolingual PDF with the original layout preserved (formulas, figures, and two-column layout remain intact, powered by PDFMathTranslate under the hood); set to: md to get a paragraph-by-paragraph bilingual Markdown; set to: both to output both PDF and Markdown simultaneously.
  • pdf_pick_model: Reads the GPU model and VRAM (via nvidia-smi → WMI → PCI registry), filters the pre-configured list of quantized Hunyuan HY-MT models to find ones that can be fully loaded onto the card, and returns the corresponding download links and llama-server launch commands.
  • pdf_translate_doctor: Reports the Python environment managed by the plugin, the pdf2zh version, the session model, the local inference service, the DeepSeek API key, and the translation cache location, for troubleshooting environment issues.

Installation & Enablement

Before installing, you need a Python 3.12 environment, with pdf2zh and pymupdf installed, and dependency versions and proxy settings properly configured. The plugin first looks for Python under $DSH_HOME/pdf-translate/venv; you can also specify an alternative path via the pythonPath field in the configuration file.

uv venv --python 3.12 "$env:DSH_HOME\pdf-translate\venv"
uv pip install --python "$env:DSH_HOME\pdf-translate\venv\Scripts\python.exe" pdf2zh "bitstring<5" pymupdf

When installing dependencies, note two version pins: bitstring<5 is required because babeldoc still imports the legacy BitStream API; and IPv6 entries in NO_PROXY that contain brackets (e.g., [::1]) will cause httpx to throw errors — the plugin automatically strips these entries at startup.

To add the plugin in DeepSeek Harness:

  • Via npm: go to Plugins → Add plugin, and type dsh-pdf-zh.
  • Via a local checkout: go to Plugins → Add plugin → pick this directory.

After installation, a Loader row named pdf-translate will appear.

Typical Usage

1. Selecting a Local Model

Run pdf_pick_model first. It inspects your current GPU and returns a suitable model along with its download and launch commands. For example, on a 4 GB VRAM card, it recommends HY-MT1.5-1.8B·Q6_K (approximately 1.37 GB, near-lossless quantization, fast inference). Once you have the command, start the model on llama-server and write localBaseUrl and localModel into the Harness plugin configuration:

localBaseUrl: http://127.0.0.1:9931/v1
localModel: hymt

2. Running a Translation

Call pdf_translate in Harness, specifying the input PDF and the output format. For example:

  • Bilingual PDF with preserved layout: pdf_translate: { input: "paper.pdf", to: "pdf" }
  • Paragraph-by-paragraph bilingual Markdown: pdf_translate: { input: "paper.pdf", to: "md" }
  • Both PDF and Markdown output: pdf_translate: { input: "paper.pdf", to: "both" }

3. Translation Routing

The plugin provides multiple translation routes. The default is engine: auto, which tries local → deepseek → dsh in order.

  • local: Uses a local llama-server (or Ollama, LM Studio, etc.) — any OpenAI-compatible endpoint — running an HY-MT GGUF model. Free after the initial download, and capable of performing both PDF layout detection and translation fully offline.
  • dsh: Reuses the session model already selected in Harness. No extra API key needed, but it only outputs Markdown; PDF layout extraction requires calling a separate OpenAI-compatible endpoint.
  • deepseek: Calls the DeepSeek API directly. Extremely low cost (roughly ¥0.3–0.5 for a 30-page paper), but requires a DeepSeek API key.
  • free: Uses the built-in Google/Bing free translation interfaces in pdf2zh. Zero cost, but may be unavailable in certain network environments (translate.google.com and www.bing.com return SSL EOF errors; translate.googleapis.com returns 429).

4. Medical / Biological Terminology Handling

The plugin ships with approximately 55 bilingual medical/biological term pairs (e.g., macrophage → 巨噬细胞, antigen presentation → 抗原呈递, progression-free survival → 无进展生存期, single-cell RNA sequencing → 单细胞 RNA 测序, etc.) and injects them into the prompt on the md route, instructing the model to preserve gene names, protein symbols, abbreviations, and statistical notation verbatim. You can modify or extend the BIOMED_GLOSSARY array in index.js. Note: the md route supports terminology intervention; the pdf route relies solely on pdf2zh’s built-in prompting strategy.

5. Token-Saving Mechanisms

The plugin reduces cost through several measures:

  • Uses PyMuPDF locally to extract text (layout-block-aware), so page images are never sent to the model; image tokens cost far more than text tokens.
  • Merges paragraphs into a single request (approximately 3,500 characters) to amortize the system prompt overhead.
  • Writes each completed translation segment to a cache ($DSH_HOME/pdf-translate/cache.json, indexed by engine, model, and source file hash), so repeated sentences, headers, and footers are translated only once (use force: true to force a re-translation).
  • Automatically skips reference lists (which typically do not need translation).
  • pdf2zh itself maintains a translation cache, so re-running the same paper consumes virtually no extra tokens.

Use Cases & Caveats

  • Ideal for users who need to quickly read English research PDFs while preserving the original layout.
  • The plugin runs with the privileges of the current DSH process; review the source code and license (MIT) before installing.
  • Supports English → Simplified Chinese only; other language directions are untested.
  • Scanned PDFs (pure images) require OCR. The plugin does not currently enable pdf2zh’s OCR feature, so the md route will be unable to extract text.
  • Interpreter discovery assumes a Windows layout (venv/Scripts/python.exe); on Linux and macOS, you must explicitly specify the path via pythonPath.
  • Output is machine-translated text. Verify numbers, gene names, and units against the original before citing.

Summary

dsh-pdf-zh decomposes the task of “translating an English research PDF” into: a layout-preserving PDF output, a citable Markdown draft, and GPU-aware local model recommendations. It offers multi-route selection across local, DeepSeek, and free backends, and includes medical-terminology constraints and token-saving mechanisms, making it well suited for processing research literature in local or private environments.

Ecosystem Context

The DeepSeek Harness plugin system allows extending capabilities within the Harness itself. The community directory (skillhub.cn/plugins) provides an index for plugins and has no official affiliation with DeepSeek or High-Flyer.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye