Make LLM batch translation thresholds configurable to reduce API calls for multi-page PDFs#591
Open
reflyable wants to merge 2 commits into
Open
Make LLM batch translation thresholds configurable to reduce API calls for multi-page PDFs#591reflyable wants to merge 2 commits into
reflyable wants to merge 2 commits into
Conversation
awwaawwa
requested changes
May 14, 2026
There was a problem hiding this comment.
1 issue found across 2 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="babeldoc/format/pdf/translation_config.py">
<violation number="1" location="babeldoc/format/pdf/translation_config.py:220">
P1: LLM batch defaults (200 tokens/5 paragraphs) contradict PR goal of larger batches to reduce API calls</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Title
[PR] Make LLM batch translation thresholds configurable to reduce API calls for multi-page PDFs
Motivation and Context
Summary of Changes
When translating multi-page PDFs, the LLM batch translation thresholds were hardcoded to 200 tokens or 5 paragraphs. This caused excessive fragmentation: a 30-page PDF with ~10 paragraphs per page would generate 90–150 individual LLM API calls. Each call incurs rate-limiter queuing, network round-trip time, and LLM inference overhead, making the translation of long documents unnecessarily slow.
PR Type
Breaking Changes
Default behavior now packs more paragraphs per LLM request, which may increase individual request latency but significantly reduces the total number of API calls. Users can tune the thresholds via CLI or config file to match their model's context window and desired latency profile.
Contributor Checklist
Summary by cubic
Makes LLM batch translation thresholds configurable to pack more paragraphs per request and cut API calls for multi-page PDFs. Defaults match previous behavior (200 tokens, 5 paragraphs), so you can opt in to larger batches as needed.
--llm-batch-max-tokensand--llm-batch-max-paragraphsto control batch sizing.TranslationConfiginstead of hardcoded values.Written for commit d7e3c4f. Summary will update on new commits.