实现自动生成术语表

This commit is contained in:
xunbu
2025-08-28 11:52:25 +08:00
parent 12958effd3
commit 56f5f4023e
15 changed files with 221 additions and 13 deletions

View File

@@ -37,6 +37,9 @@ class MDTranslator(AiTranslator):
self.logger.info("正在翻译markdown")
with MDMaskUrisContext(document):
chunks: list[str] = split_markdown_text(document.content.decode(), self.chunk_size)
if self.glossary_agent:
glossary_dict = self.glossary_agent.send_segments(chunks, self.chunk_size)
self.translate_agent.update_glossary_dict(glossary_dict)
self.logger.info(f"markdown分为{len(chunks)}")
result: list[str] = self.translate_agent.send_chunks(chunks)
content = join_markdown_texts(result)
@@ -52,6 +55,11 @@ class MDTranslator(AiTranslator):
self.logger.info("正在翻译markdown")
with MDMaskUrisContext(document):
chunks: list[str] = split_markdown_text(document.content.decode(), self.chunk_size)
if self.glossary_agent:
glossary_dict = await self.glossary_agent.send_segments_async(chunks, self.chunk_size)
self.translate_agent.update_glossary_dict(glossary_dict)
self.logger.info(f"markdown分为{len(chunks)}")
result: list[str] = await self.translate_agent.send_chunks_async(chunks)