增加txt不分段选项

This commit is contained in:
xunbu
2025-11-09 19:18:28 +08:00
parent ad9f01c2b1
commit a67ede5820
5 changed files with 80 additions and 147 deletions

View File

@@ -183,7 +183,6 @@ class SegmentsTranslateAgent(Agent):
def send_segments(self, segments: list[str], chunk_size: int) -> list[str]: def send_segments(self, segments: list[str], chunk_size: int) -> list[str]:
indexed_originals, chunks, merged_indices_list = segments2json_chunks(segments, chunk_size) indexed_originals, chunks, merged_indices_list = segments2json_chunks(segments, chunk_size)
prompts = [generate_prompt(json.dumps(chunk, ensure_ascii=False, indent=0), self.to_lang) for chunk in 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.json_format, translated_chunks = super().send_prompts(prompts=prompts, json_format=self.json_format,
pre_send_handler=self._pre_send_handler, pre_send_handler=self._pre_send_handler,
result_handler=self._result_handler, result_handler=self._result_handler,
@@ -227,7 +226,6 @@ class SegmentsTranslateAgent(Agent):
pre_send_handler=self._pre_send_handler, pre_send_handler=self._pre_send_handler,
result_handler=self._result_handler, result_handler=self._result_handler,
error_result_handler=self._error_result_handler) error_result_handler=self._error_result_handler)
indexed_translated = indexed_originals.copy() indexed_translated = indexed_originals.copy()
for chunk in translated_chunks: for chunk in translated_chunks:
try: try:

View File

@@ -469,9 +469,9 @@ class TextWorkflowParams(BaseWorkflowParams):
"\n", "\n",
description="当 insert_mode 为 'append''prepend' 时,用于分隔原文和译文的分隔符。", description="当 insert_mode 为 'append''prepend' 时,用于分隔原文和译文的分隔符。",
) )
segment_mode: Literal["line", "paragraph"] = Field( segment_mode: Literal["line", "paragraph", "none"] = Field(
"line", "line",
description="分段模式。'line':按行分段(每行独立翻译),'paragraph':按段落分段(连续非空行合并为段落)。", description="分段模式。'line':按行分段(每行独立翻译),'paragraph':按段落分段(连续非空行合并为段落)'none':不分段(全文视为一个段落)",
) )

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -24,11 +24,12 @@ class TXTTranslatorConfig(AiTranslatorConfig):
separator (str): separator (str):
"append""prepend" 模式下,用于分隔原文和译文的字符串。 "append""prepend" 模式下,用于分隔原文和译文的字符串。
默认为换行符 "\n" 默认为换行符 "\n"
segment_mode (Literal["line", "paragraph"]): segment_mode (Literal["line", "paragraph", "none"]):
分段模式。 分段模式。
- "line": 按行分段(每行独立翻译) - "line": 按行分段(每行独立翻译)
- "paragraph": 按段落分段(连续非空行合并为段落) - "paragraph": 按段落分段(连续非空行合并为段落)
默认为 "paragraph" - "none": 不分段(全文视为一个段落)
默认为 "line"
""" """
insert_mode: Literal["replace", "append", "prepend"] = "replace" insert_mode: Literal["replace", "append", "prepend"] = "replace"
separator: str = "\n" separator: str = "\n"