Skip to content

Add Google Translate engine for paper PDF jobs - #19

Draft
znsoftm wants to merge 1 commit into
cursor/papers-hf-daily-fe66from
cursor/papers-google-translate-f7ae
Draft

znsoftm wants to merge 1 commit into
cursor/papers-hf-daily-fe66from
cursor/papers-google-translate-f7ae

Conversation

@znsoftm

@znsoftm znsoftm commented Sep 15, 2026

Copy link
Copy Markdown
Member

Hub admins can now pick Google Translate for paper PDF translation in Settings (/settings, papers translate section). The choice persists in $PAPERS_DIR/translate-config.json and applies to new BabelDOC jobs without a redeploy.

Why a shim (not --google)

Current BabelDOC (0.6.x on the papers stack) only exposes --openai. Older BabelDOC/pdf2zh builds had --google; this one does not. Inventing a fake engine that still called Hub would not meet the goal.

This PR keeps BabelDOC on --openai and points it at a local OpenAI-compatible shim that actually calls Google:

  1. Google Cloud Translation API v2 when an optional google_api_key is saved
  2. Otherwise the public Google Translate web endpoints (translate.googleapis.com/translate_a/single, fallback translate.google.com/m) — the same family pdf2zh-next uses

The Python worker (agent-papers/google_translate.py + translate_worker.py) is the primary path. The Go BabelDOC fallback starts the same kind of shim.

What stays on Hub LLM

engine is PDF-only. Abstract ZH, paper review, and Hugging Face daily trend still use the existing Hub / OpenAI-compatible snapshot (base_url / api_key / model). Those need chat completions; Google is a machine-translation path, not a chat model.

Settings / credentials

  • Radio: Hub / OpenAI-compatible LLM vs Google 翻译 / Google Translate
  • Active-engine badge + short hint that Google is faster but quality/layout may differ
  • Optional masked Google Cloud Translation API key (google_api_key); empty does not wipe; clear_google_api_key deletes
  • No secrets committed (translate-config.json remains gitignored)
  • Same Hub global-admin auth as existing settings
  • zh/en i18n for the new labels
  • Test button pings Google when Google is selected (Cloud if a key is present, else the web endpoint)

Tests

  • Config persistence, engine validation, Google-without-Hub-key job routing, Hub-still-requires-key
  • Google Cloud vs web client routing, placeholder protection, OpenAI shim extracts BabelDOC Input: payload only
  • Settings HTML includes the engine control
  • Python unit tests for extract / routing / shim

Ops notes

  • Google selected + Cloud key: uses paid Cloud Translation; auth failures fail clearly (no silent Hub fallback)
  • Google selected + no key: uses the public web path (works without a paid key; may be rate-limited)
  • Hub selected: today’s BabelDOC --openai + translate-config behavior unchanged
Open in Web Open in Cursor 

BabelDOC 0.6.x only exposes --openai, so Google jobs run through a local
OpenAI-compatible shim that calls Cloud Translation API (optional key)
or the public Google Translate web endpoint. Hub LLM settings stay in
place for abstract_zh, paper review, and HF daily trend.

Co-authored-by: Daniel <znsoft@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants