From d74fa46f9df03453b69d284548cf96df7a91ca25 Mon Sep 17 00:00:00 2001 From: refly <3380520452@qq.com> Date: Tue, 12 May 2026 19:28:52 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20LLM=20=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E7=BF=BB=E8=AF=91=E8=AF=B7=E6=B1=82=E7=9A=84=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E4=BB=A4=E7=89=8C=E5=92=8C=E6=AE=B5=E8=90=BD=E6=95=B0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../document_il/midend/il_translator_llm_only.py | 2 +- babeldoc/format/pdf/translation_config.py | 4 ++++ babeldoc/main.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/babeldoc/format/pdf/document_il/midend/il_translator_llm_only.py b/babeldoc/format/pdf/document_il/midend/il_translator_llm_only.py index cef6e069..fe210a25 100644 --- a/babeldoc/format/pdf/document_il/midend/il_translator_llm_only.py +++ b/babeldoc/format/pdf/document_il/midend/il_translator_llm_only.py @@ -589,7 +589,7 @@ def process_page( ) ) - if total_token_count > 200 or len(paragraphs) > 5: + if total_token_count > self.translation_config.llm_batch_max_tokens or len(paragraphs) > self.translation_config.llm_batch_max_paragraphs: self.mid += 1 executor.submit( self.translate_paragraph, diff --git a/babeldoc/format/pdf/translation_config.py b/babeldoc/format/pdf/translation_config.py index 3270b591..29b182c7 100644 --- a/babeldoc/format/pdf/translation_config.py +++ b/babeldoc/format/pdf/translation_config.py @@ -217,6 +217,8 @@ def __init__( metadata_extra_data: str | None = None, term_pool_max_workers: int | None = None, disable_same_text_fallback: bool = False, + llm_batch_max_tokens: int = 2000, + llm_batch_max_paragraphs: int = 30, ): self.translator = translator self.term_extraction_translator = term_extraction_translator or translator @@ -376,6 +378,8 @@ def __init__( "cache_hit_prompt_tokens": 0, } self.disable_same_text_fallback = disable_same_text_fallback + self.llm_batch_max_tokens = llm_batch_max_tokens + self.llm_batch_max_paragraphs = llm_batch_max_paragraphs if self.ocr_workaround: self.remove_non_formula_lines = False diff --git a/babeldoc/main.py b/babeldoc/main.py index 9e256e10..1895ae41 100644 --- a/babeldoc/main.py +++ b/babeldoc/main.py @@ -291,6 +291,18 @@ def create_parser(): type=int, help="Maximum number of worker threads dedicated to automatic term extraction. If not specified, defaults to --pool-max-workers (or QPS value when unset).", ) + translation_group.add_argument( + "--llm-batch-max-tokens", + type=int, + default=2000, + help="Maximum total tokens per LLM batch translation request. Paragraphs are packed until this limit is reached. (default: 2000)", + ) + translation_group.add_argument( + "--llm-batch-max-paragraphs", + type=int, + default=30, + help="Maximum number of paragraphs per LLM batch translation request. Paragraphs are packed until this limit is reached. (default: 30)", + ) translation_group.add_argument( "--no-auto-extract-glossary", action="store_false", @@ -729,6 +741,8 @@ async def main(): skip_formula_offset_calculation=args.skip_formula_offset_calculation, metadata_extra_data=args.metadata_extra_data, term_pool_max_workers=args.term_pool_max_workers, + llm_batch_max_tokens=args.llm_batch_max_tokens, + llm_batch_max_paragraphs=args.llm_batch_max_paragraphs, ) def nop(_x): From d7e3c4f1230780d20ef1916add7822a083f2b279 Mon Sep 17 00:00:00 2001 From: refly <3380520452@qq.com> Date: Thu, 14 May 2026 20:11:00 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=20LLM=20=E6=89=B9?= =?UTF-8?q?=E9=87=8F=E7=BF=BB=E8=AF=91=E8=AF=B7=E6=B1=82=E7=9A=84=E6=9C=80?= =?UTF-8?q?=E5=A4=A7=E4=BB=A4=E7=89=8C=E5=92=8C=E6=AE=B5=E8=90=BD=E6=95=B0?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- babeldoc/format/pdf/translation_config.py | 4 ++-- babeldoc/main.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/babeldoc/format/pdf/translation_config.py b/babeldoc/format/pdf/translation_config.py index 29b182c7..14da500e 100644 --- a/babeldoc/format/pdf/translation_config.py +++ b/babeldoc/format/pdf/translation_config.py @@ -217,8 +217,8 @@ def __init__( metadata_extra_data: str | None = None, term_pool_max_workers: int | None = None, disable_same_text_fallback: bool = False, - llm_batch_max_tokens: int = 2000, - llm_batch_max_paragraphs: int = 30, + llm_batch_max_tokens: int = 200, + llm_batch_max_paragraphs: int = 5, ): self.translator = translator self.term_extraction_translator = term_extraction_translator or translator diff --git a/babeldoc/main.py b/babeldoc/main.py index 1895ae41..941332c8 100644 --- a/babeldoc/main.py +++ b/babeldoc/main.py @@ -294,14 +294,14 @@ def create_parser(): translation_group.add_argument( "--llm-batch-max-tokens", type=int, - default=2000, - help="Maximum total tokens per LLM batch translation request. Paragraphs are packed until this limit is reached. (default: 2000)", + default=200, + help="Maximum total tokens per LLM batch translation request. Paragraphs are packed until this limit is reached. (default: 200)", ) translation_group.add_argument( "--llm-batch-max-paragraphs", type=int, - default=30, - help="Maximum number of paragraphs per LLM batch translation request. Paragraphs are packed until this limit is reached. (default: 30)", + default=5, + help="Maximum number of paragraphs per LLM batch translation request. Paragraphs are packed until this limit is reached. (default: 5)", ) translation_group.add_argument( "--no-auto-extract-glossary",