perf: bump default chunk_size 1000 -> 6000 + log chunk stats

Root cause of 24-min translation: frontend default chunk_size was 1000
(upstream xunbu default), producing 78 requests for the client's WI
document (verified by running segments2json_chunks on the real file:
1000 -> 78 chunks, matches server log's '75 requests').

- index.html: default chunk_size 1000 -> 6000 (78 -> 13 requests, 6x
  fewer). 6000 is safe vs qwen3.6-plus 8-16K output limit, and gives
  the LLM MORE context (better terminology consistency). Slider range
  already allows up to 12000.
- segments_agent.py: log segment count / total chars / chunk_size /
  expected request count after chunking, so 'slow translation' reports
  can be diagnosed instantly (doc structure vs chunk size vs API latency).
This commit is contained in:
2026-07-28 10:11:19 +08:00
parent 13c8732c42
commit 20cf8f8188
2 changed files with 10 additions and 2 deletions

View File

@@ -323,6 +323,10 @@ class SegmentsTranslateAgent(Agent):
# Non-MT mode: JSON batch translation
indexed_originals, chunks, merged_indices_list = segments2json_chunks(segments, chunk_size)
self.logger.info(
f"分块统计: 段数={len(segments)}, 总字符={sum(len(s) for s in segments)}, "
f"chunk_size={chunk_size}, 预计请求={len(chunks)}"
)
prompts = [generate_prompt(json.dumps(chunk, ensure_ascii=False, indent=0), self.to_lang) for chunk in chunks]
translated_chunks = super().send_prompts(prompts=prompts, json_format=self.force_json,
pre_send_handler=self._pre_send_handler,
@@ -414,6 +418,10 @@ class SegmentsTranslateAgent(Agent):
# Non-MT mode: JSON batch translation
indexed_originals, chunks, merged_indices_list = await asyncio.to_thread(segments2json_chunks, segments,
chunk_size)
self.logger.info(
f"分块统计: 段数={len(segments)}, 总字符={sum(len(s) for s in segments)}, "
f"chunk_size={chunk_size}, 预计请求={len(chunks)}"
)
prompts = [generate_prompt(json.dumps(chunk, ensure_ascii=False, indent=0), self.to_lang) for chunk in chunks]
translated_chunks = await super().send_prompts_async(prompts=prompts, force_json=self.force_json,
pre_send_handler=self._pre_send_handler,

View File

@@ -1120,7 +1120,7 @@
custom_to_lang: '',
thinking: 'disable',
custom_prompt: '',
chunk_size: 1000,
chunk_size: 6000,
concurrent: 5,
temperature: 0.1,
retry: 3,
@@ -1187,7 +1187,7 @@
form.custom_to_lang = get('translator_custom_to_lang', '');
form.thinking = get('translator_thinking_mode', 'default');
form.custom_prompt = get('custom_prompt', '');
form.chunk_size = getNum('chunk_size', 1000);
form.chunk_size = getNum('chunk_size', 6000);
form.concurrent = getNum('concurrent', 5);
form.temperature = getNum('temperature', 0.1);
form.retry = getNum('retry', 3);