config去掉system_prompt

This commit is contained in:
xunbu committed 2025-08-28 16:43:23 +08:00
1 parent 56f5f4023e
commit 7192b961c7
16 files changed
+207 -121

No files matched your search

+11 -9
View File
@@ -26,7 +26,6 @@ class AgentConfig:
baseurl: str baseurl: str
key: str key: str
model_id: str model_id: str
system_prompt: str | None
temperature: float = 0.7 temperature: float = 0.7
max_concurrent: int = 30 max_concurrent: int = 30
timeout: int = 2000 timeout: int = 2000
@@ -68,8 +67,8 @@ class PromptsCounter:
PreSendHandlerType = Callable[[str, str], tuple[str, str]] PreSendHandlerType = Callable[[str, str], tuple[str, str]]
ResultHandlerType = Callable[[str, str, logging.Logger], str] ResultHandlerType = Callable[[str, str, logging.Logger], Any]
ErrorResultHandlerType = Callable[[str, logging.Logger], str] ErrorResultHandlerType = Callable[[str, logging.Logger], Any]
class Agent: class Agent:
@@ -90,7 +89,7 @@ class Agent:
self.domain = urlparse(self.baseurl).netloc self.domain = urlparse(self.baseurl).netloc
self.key = config.key.strip() or "xx" self.key = config.key.strip() or "xx"
self.model_id = config.model_id.strip() self.model_id = config.model_id.strip()
self.system_prompt = config.system_prompt or "" self.system_prompt = ""
self.temperature = config.temperature self.temperature = config.temperature
self.max_concurrent = config.max_concurrent self.max_concurrent = config.max_concurrent
self.timeout = config.timeout self.timeout = config.timeout
@@ -158,6 +157,8 @@ class Agent:
self.logger.warning(f"AI请求连接错误 (async): {repr(e)}") self.logger.warning(f"AI请求连接错误 (async): {repr(e)}")
except (KeyError, IndexError) as e: except (KeyError, IndexError) as e:
raise Exception(f"AI响应格式错误 (async): {repr(e)}") raise Exception(f"AI响应格式错误 (async): {repr(e)}")
except ValueError as e:
self.logger.warning(f"{e.__repr__()}")
# 如果没有正常获取结果则重试 # 如果没有正常获取结果则重试
if retry and retry_count < MAX_RETRY_COUNT: if retry and retry_count < MAX_RETRY_COUNT:
if self.total_error_counter.add(): if self.total_error_counter.add():
@@ -181,7 +182,7 @@ class Agent:
) -> list[Any]: ) -> list[Any]:
max_concurrent = self.max_concurrent if max_concurrent is None else max_concurrent max_concurrent = self.max_concurrent if max_concurrent is None else max_concurrent
total = len(prompts) total = len(prompts)
self.logger.info(f"base-url:{self.baseurl},model-id:{self.model_id}") self.logger.info(f"base-url:{self.baseurl},model-id:{self.model_id},concurrent:{self.max_concurrent},temperature:{self.temperature}")
self.logger.info(f"预计发送{total}个请求,并发请求数:{max_concurrent}") self.logger.info(f"预计发送{total}个请求,并发请求数:{max_concurrent}")
self.total_error_counter.max_errors_count = len(prompts) // MAX_REQUESTS_PER_ERROR # 允许多少个异常 self.total_error_counter.max_errors_count = len(prompts) // MAX_REQUESTS_PER_ERROR # 允许多少个异常
count = 0 count = 0
@@ -258,7 +259,8 @@ class Agent:
pre_send_handler, pre_send_handler,
result_handler, result_handler,
error_result_handler) -> Any: error_result_handler) -> Any:
result = self.send(client, prompt, system_prompt, pre_send_handler=pre_send_handler,result_handler=result_handler, result = self.send(client, prompt, system_prompt, pre_send_handler=pre_send_handler,
result_handler=result_handler,
error_result_handler=error_result_handler) error_result_handler=error_result_handler)
count.add() count.add()
return result return result
@@ -267,11 +269,11 @@ class Agent:
self, self,
prompts: list[str], prompts: list[str],
system_prompt: str | None = None, system_prompt: str | None = None,
pre_send_handler:PreSendHandlerType=None, pre_send_handler: PreSendHandlerType = None,
result_handler: ResultHandlerType = None, result_handler: ResultHandlerType = None,
error_result_handler: ErrorResultHandlerType = None error_result_handler: ErrorResultHandlerType = None
) -> list[Any]: ) -> list[Any]:
self.logger.info(f"base-url:{self.baseurl},model-id:{self.model_id}") self.logger.info(f"base-url:{self.baseurl},model-id:{self.model_id},concurrent:{self.max_concurrent},temperature:{self.temperature}")
self.logger.info(f"预计发送{len(prompts)}个请求,并发请求数:{self.max_concurrent}") self.logger.info(f"预计发送{len(prompts)}个请求,并发请求数:{self.max_concurrent}")
self.total_error_counter.max_errors_count = len(prompts) // MAX_REQUESTS_PER_ERROR # 允许多少个异常 self.total_error_counter.max_errors_count = len(prompts) // MAX_REQUESTS_PER_ERROR # 允许多少个异常
# 创建单个计数器实例 # 创建单个计数器实例
@@ -280,7 +282,7 @@ class Agent:
# 使用 itertools.repeat 将同一个实例传递给每个 map 调用 # 使用 itertools.repeat 将同一个实例传递给每个 map 调用
system_prompts = itertools.repeat(system_prompt, len(prompts)) system_prompts = itertools.repeat(system_prompt, len(prompts))
counters = itertools.repeat(counter, len(prompts)) counters = itertools.repeat(counter, len(prompts))
pre_send_handlers=itertools.repeat(pre_send_handler,len(prompts)) pre_send_handlers = itertools.repeat(pre_send_handler, len(prompts))
result_handlers = itertools.repeat(result_handler, len(prompts)) result_handlers = itertools.repeat(result_handler, len(prompts))
error_result_handlers = itertools.repeat(error_result_handler, len(prompts)) error_result_handlers = itertools.repeat(error_result_handler, len(prompts))
output_list = [] output_list = []
+7 -2
View File
@@ -46,6 +46,8 @@ You are a professional machine translation engine.
""" """
def _result_handler(self, result: str, origin_prompt: str, logger: Logger): def _result_handler(self, result: str, origin_prompt: str, logger: Logger):
if result == "":
return []
try: try:
result = json_repair.loads(result) result = json_repair.loads(result)
if not isinstance(result, list): if not isinstance(result, list):
@@ -56,6 +58,8 @@ You are a professional machine translation engine.
return result return result
def _error_result_handler(self, origin_prompt: str, logger: Logger): def _error_result_handler(self, origin_prompt: str, logger: Logger):
if origin_prompt == "":
return []
try: try:
return json_repair.loads(origin_prompt) return json_repair.loads(origin_prompt)
except: except:
@@ -79,11 +83,11 @@ You are a professional machine translation engine.
self.logger.info(f"json解析错误,解析文本:{chunk},错误:{e.__repr__()}") self.logger.info(f"json解析错误,解析文本:{chunk},错误:{e.__repr__()}")
except Exception as e: except Exception as e:
self.logger.info(f"send_segments发生错误:{e.__repr__()}") self.logger.info(f"send_segments发生错误:{e.__repr__()}")
self.logger.info("术语表提取完成")
return result return result
async def send_segments_async(self, segments: list[str], chunk_size: int): async def send_segments_async(self, segments: list[str], chunk_size: int):
self.logger.info("开始提取术语表") self.logger.info("开始术语表提取")
result = {} result = {}
indexed_originals, chunks, merged_indices_list = await asyncio.to_thread(segments2json_chunks, segments, indexed_originals, chunks, merged_indices_list = await asyncio.to_thread(segments2json_chunks, segments,
chunk_size) chunk_size)
@@ -101,4 +105,5 @@ You are a professional machine translation engine.
except Exception as e: except Exception as e:
self.logger.info(f"send_segments发生错误:{e.__repr__()}") self.logger.info(f"send_segments发生错误:{e.__repr__()}")
print(f"术语表:\n{result}") print(f"术语表:\n{result}")
self.logger.info("术语表提取完成")
return result return result
+7 -4
View File
@@ -57,16 +57,19 @@ Warning: Never wrap the entire JSON object in quotes to make it a single string.
return system_prompt, prompt return system_prompt, prompt
def _result_handler(self, result: str, origin_prompt: str, logger: Logger): def _result_handler(self, result: str, origin_prompt: str, logger: Logger):
if result == "":
return {}
try: try:
result = json_repair.loads(result) result = json_repair.loads(result)
if not isinstance(result, dict): if not isinstance(result, dict):
raise ValueError("agent返回结果不是dict的json形式") raise ValueError(f"agent返回结果不是dict的json形式,result:{result}")
except: except RuntimeError as e:
logger.error("结果不能正确解析") raise ValueError(f"结果不能正确解析:{e.__repr__()}")
return self._error_result_handler(origin_prompt, logger)
return result return result
def _error_result_handler(self, origin_prompt: str, logger: Logger): def _error_result_handler(self, origin_prompt: str, logger: Logger):
if origin_prompt == "":
return {}
try: try:
return json_repair.loads(origin_prompt) return json_repair.loads(origin_prompt)
except: except:
+94 -26
View File
@@ -22,6 +22,7 @@ from pydantic import BaseModel, Field, field_validator
from docutranslate import __version__ from docutranslate import __version__
from docutranslate.agents.agent import ThinkingMode from docutranslate.agents.agent import ThinkingMode
from docutranslate.agents.glossary_agent import GlossaryAgentConfig
from docutranslate.exporter.md.types import ConvertEngineType from docutranslate.exporter.md.types import ConvertEngineType
# --- 核心代码 Imports --- # --- 核心代码 Imports ---
from docutranslate.global_values.conditional_import import DOCLING_EXIST from docutranslate.global_values.conditional_import import DOCLING_EXIST
@@ -220,6 +221,16 @@ app.mount("/static", StaticFiles(directory=STATIC_DIR), name="static")
# --- Pydantic Models for Service API --- # --- Pydantic Models for Service API ---
# =================================================================== # ===================================================================
class GlossaryAgentConfigPayload(BaseModel):
baseurl: str = Field(..., description="用于术语表生成的Agent的LLM API基础URL。", examples=["https://api.openai.com/v1"])
key: str = Field(..., description="用于术语表生成的Agent的LLM API密钥。", examples=["sk-agent-api-key"])
model_id: str = Field(..., description="用于术语表生成的Agent的模型ID。", examples=["gpt-4-turbo"])
temperature: float = Field(default=0.7, description="用于术语表生成的Agent的温度参数。")
max_concurrent: int = Field(default=30, description="Agent的最大并发请求数。")
timeout: int = Field(default=2000, description="Agent的API调用超时时间。")
thinking: ThinkingMode = Field(default="default", description="Agent的思考模式。")
# 1. 定义所有工作流共享的基础参数 # 1. 定义所有工作流共享的基础参数
class BaseWorkflowParams(BaseModel): class BaseWorkflowParams(BaseModel):
base_url: str = Field(..., description="LLM API的基础URL。", examples=["https://api.openai.com/v1"]) base_url: str = Field(..., description="LLM API的基础URL。", examples=["https://api.openai.com/v1"])
@@ -233,6 +244,15 @@ class BaseWorkflowParams(BaseModel):
examples=["default", "enable", "disable"]) examples=["default", "enable", "disable"])
custom_prompt: Optional[str] = Field(None, description="用户自定义的翻译Prompt。", alias="custom_prompt") custom_prompt: Optional[str] = Field(None, description="用户自定义的翻译Prompt。", alias="custom_prompt")
glossary_dict: Optional[Dict[str, str]] = Field(None, description="术语表字典,key为原文,value为译文。") glossary_dict: Optional[Dict[str, str]] = Field(None, description="术语表字典,key为原文,value为译文。")
glossary_generate_enable: bool = Field(default=False, description="是否开启术语表自动生成。")
glossary_agent_config: Optional[GlossaryAgentConfigPayload] = Field(None,
description="用于术语表生成的Agent的配置。如果 `glossary_generate_enable` 为 `True`,此项必填。")
@field_validator('glossary_agent_config')
def check_glossary_config(cls, v, values):
if values.data.get('glossary_generate_enable') and not v:
raise ValueError("当 `glossary_generate_enable` 为 `True` 时, `glossary_agent_config` 字段是必须的。")
return v
# 2. 为每个工作流创建独立的参数模型 # 2. 为每个工作流创建独立的参数模型
@@ -410,6 +430,27 @@ class TranslateServiceRequest(BaseModel):
} }
} }
}, },
{
"summary": "XLSX 带术语表生成",
"value": {
"file_name": "complex_terms.xlsx",
"file_content": "UEsDBBQAAAAIA... (base64-encoded xlsx)",
"payload": {
"workflow_type": "xlsx",
"base_url": "https://api.openai.com/v1",
"api_key": "sk-your-main-translator-key",
"model_id": "gpt-4o",
"to_lang": "简体中文",
"glossary_generate_enable": True,
"glossary_agent_config": {
"baseurl": "https://api.openai.com/v1",
"key": "sk-your-agent-key-for-glossary",
"model_id": "gpt-4-turbo",
"temperature": 0.5
}
}
}
},
{ {
"summary": "DOCX 工作流示例", "summary": "DOCX 工作流示例",
"value": { "value": {
@@ -508,15 +549,28 @@ async def _perform_translation(
workflow: Workflow workflow: Workflow
# 辅助函数:构建术语表生成配置
def build_glossary_agent_config():
if payload.glossary_generate_enable and payload.glossary_agent_config:
agent_payload = payload.glossary_agent_config
return GlossaryAgentConfig(
logger=task_logger,
to_lang=payload.to_lang,
**agent_payload.model_dump()
)
return None
# 2. 根据 payload 的具体类型构建配置并实例化 workflow # 2. 根据 payload 的具体类型构建配置并实例化 workflow
if isinstance(payload, MarkdownWorkflowParams): if isinstance(payload, MarkdownWorkflowParams):
task_logger.info("构建 MarkdownBasedWorkflow 配置。") task_logger.info("构建 MarkdownBasedWorkflow 配置。")
translator_config = MDTranslatorConfig( translator_args = payload.model_dump(include={
**payload.model_dump(include={
'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt', 'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt',
'temperature', 'thinking', 'chunk_size', 'concurrent', 'glossary_dict' 'temperature', 'thinking', 'chunk_size', 'concurrent', 'glossary_dict'
}, exclude_none=True) }, exclude_none=True)
) translator_args['glossary_generate_enable'] = payload.glossary_generate_enable
translator_args['glossary_agent_config'] = build_glossary_agent_config()
translator_config = MDTranslatorConfig(**translator_args)
converter_config = None converter_config = None
if payload.convert_engine == 'mineru': if payload.convert_engine == 'mineru':
converter_config = ConverterMineruConfig(logger=task_logger, mineru_token=payload.mineru_token, converter_config = ConverterMineruConfig(logger=task_logger, mineru_token=payload.mineru_token,
@@ -535,12 +589,14 @@ async def _perform_translation(
elif isinstance(payload, TextWorkflowParams): elif isinstance(payload, TextWorkflowParams):
task_logger.info("构建 TXTWorkflow 配置。") task_logger.info("构建 TXTWorkflow 配置。")
translator_config = TXTTranslatorConfig( translator_args = payload.model_dump(include={
**payload.model_dump(include={
'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt', 'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt',
'temperature', 'thinking', 'chunk_size', 'concurrent', 'glossary_dict' 'temperature', 'thinking', 'chunk_size', 'concurrent', 'glossary_dict'
}, exclude_none=True) }, exclude_none=True)
) translator_args['glossary_generate_enable'] = payload.glossary_generate_enable
translator_args['glossary_agent_config'] = build_glossary_agent_config()
translator_config = TXTTranslatorConfig(**translator_args)
html_exporter_config = TXT2HTMLExporterConfig(cdn=True) html_exporter_config = TXT2HTMLExporterConfig(cdn=True)
workflow_config = TXTWorkflowConfig( workflow_config = TXTWorkflowConfig(
translator_config=translator_config, html_exporter_config=html_exporter_config, translator_config=translator_config, html_exporter_config=html_exporter_config,
@@ -550,13 +606,15 @@ async def _perform_translation(
elif isinstance(payload, JsonWorkflowParams): elif isinstance(payload, JsonWorkflowParams):
task_logger.info("构建 JsonWorkflow 配置。") task_logger.info("构建 JsonWorkflow 配置。")
translator_config = JsonTranslatorConfig( translator_args = payload.model_dump(include={
json_paths=payload.json_paths,
**payload.model_dump(include={
'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt', 'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt',
'temperature', 'thinking', 'chunk_size', 'concurrent', 'glossary_dict' 'temperature', 'thinking', 'chunk_size', 'concurrent', 'glossary_dict',
'json_paths'
}, exclude_none=True) }, exclude_none=True)
) translator_args['glossary_generate_enable'] = payload.glossary_generate_enable
translator_args['glossary_agent_config'] = build_glossary_agent_config()
translator_config = JsonTranslatorConfig(**translator_args)
html_exporter_config = Json2HTMLExporterConfig(cdn=True) html_exporter_config = Json2HTMLExporterConfig(cdn=True)
workflow_config = JsonWorkflowConfig( workflow_config = JsonWorkflowConfig(
translator_config=translator_config, html_exporter_config=html_exporter_config, translator_config=translator_config, html_exporter_config=html_exporter_config,
@@ -566,13 +624,15 @@ async def _perform_translation(
elif isinstance(payload, XlsxWorkflowParams): elif isinstance(payload, XlsxWorkflowParams):
task_logger.info("构建 XlsxWorkflow 配置。") task_logger.info("构建 XlsxWorkflow 配置。")
translator_config = XlsxTranslatorConfig( translator_args = payload.model_dump(include={
**payload.model_dump(include={
'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt', 'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt',
'temperature', 'thinking', 'chunk_size', 'concurrent', 'temperature', 'thinking', 'chunk_size', 'concurrent',
'insert_mode', 'separator', 'translate_regions', 'glossary_dict' 'insert_mode', 'separator', 'translate_regions', 'glossary_dict'
}, exclude_none=True) }, exclude_none=True)
) translator_args['glossary_generate_enable'] = payload.glossary_generate_enable
translator_args['glossary_agent_config'] = build_glossary_agent_config()
translator_config = XlsxTranslatorConfig(**translator_args)
html_exporter_config = Xlsx2HTMLExporterConfig(cdn=True) html_exporter_config = Xlsx2HTMLExporterConfig(cdn=True)
workflow_config = XlsxWorkflowConfig( workflow_config = XlsxWorkflowConfig(
translator_config=translator_config, translator_config=translator_config,
@@ -583,13 +643,15 @@ async def _perform_translation(
elif isinstance(payload, DocxWorkflowParams): elif isinstance(payload, DocxWorkflowParams):
task_logger.info("构建 DocxWorkflow 配置。") task_logger.info("构建 DocxWorkflow 配置。")
translator_config = DocxTranslatorConfig( translator_args = payload.model_dump(include={
**payload.model_dump(include={
'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt', 'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt',
'temperature', 'thinking', 'chunk_size', 'concurrent', 'temperature', 'thinking', 'chunk_size', 'concurrent',
'insert_mode', 'separator', 'glossary_dict' 'insert_mode', 'separator', 'glossary_dict'
}, exclude_none=True) }, exclude_none=True)
) translator_args['glossary_generate_enable'] = payload.glossary_generate_enable
translator_args['glossary_agent_config'] = build_glossary_agent_config()
translator_config = DocxTranslatorConfig(**translator_args)
html_exporter_config = Docx2HTMLExporterConfig(cdn=True) html_exporter_config = Docx2HTMLExporterConfig(cdn=True)
workflow_config = DocxWorkflowConfig( workflow_config = DocxWorkflowConfig(
translator_config=translator_config, translator_config=translator_config,
@@ -600,13 +662,15 @@ async def _perform_translation(
elif isinstance(payload, SrtWorkflowParams): elif isinstance(payload, SrtWorkflowParams):
task_logger.info("构建 SrtWorkflow 配置。") task_logger.info("构建 SrtWorkflow 配置。")
translator_config = SrtTranslatorConfig( translator_args = payload.model_dump(include={
**payload.model_dump(include={
'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt', 'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt',
'temperature', 'thinking', 'chunk_size', 'concurrent', 'temperature', 'thinking', 'chunk_size', 'concurrent',
'insert_mode', 'separator', 'glossary_dict' 'insert_mode', 'separator', 'glossary_dict'
}, exclude_none=True) }, exclude_none=True)
) translator_args['glossary_generate_enable'] = payload.glossary_generate_enable
translator_args['glossary_agent_config'] = build_glossary_agent_config()
translator_config = SrtTranslatorConfig(**translator_args)
html_exporter_config = Srt2HTMLExporterConfig(cdn=True) html_exporter_config = Srt2HTMLExporterConfig(cdn=True)
workflow_config = SrtWorkflowConfig( workflow_config = SrtWorkflowConfig(
translator_config=translator_config, translator_config=translator_config,
@@ -617,13 +681,15 @@ async def _perform_translation(
elif isinstance(payload, EpubWorkflowParams): elif isinstance(payload, EpubWorkflowParams):
task_logger.info("构建 EpubWorkflow 配置。") task_logger.info("构建 EpubWorkflow 配置。")
translator_config = EpubTranslatorConfig( translator_args = payload.model_dump(include={
**payload.model_dump(include={
'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt', 'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt',
'temperature', 'thinking', 'chunk_size', 'concurrent', 'temperature', 'thinking', 'chunk_size', 'concurrent',
'insert_mode', 'separator', 'glossary_dict' 'insert_mode', 'separator', 'glossary_dict'
}, exclude_none=True) }, exclude_none=True)
) translator_args['glossary_generate_enable'] = payload.glossary_generate_enable
translator_args['glossary_agent_config'] = build_glossary_agent_config()
translator_config = EpubTranslatorConfig(**translator_args)
html_exporter_config = Epub2HTMLExporterConfig(cdn=True) html_exporter_config = Epub2HTMLExporterConfig(cdn=True)
workflow_config = EpubWorkflowConfig( workflow_config = EpubWorkflowConfig(
translator_config=translator_config, translator_config=translator_config,
@@ -635,13 +701,15 @@ async def _perform_translation(
# --- HTML WORKFLOW LOGIC START --- # --- HTML WORKFLOW LOGIC START ---
elif isinstance(payload, HtmlWorkflowParams): elif isinstance(payload, HtmlWorkflowParams):
task_logger.info("构建 HtmlWorkflow 配置。") task_logger.info("构建 HtmlWorkflow 配置。")
translator_config = HtmlTranslatorConfig( translator_args = payload.model_dump(include={
**payload.model_dump(include={
'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt', 'base_url', 'api_key', 'model_id', 'to_lang', 'custom_prompt',
'temperature', 'thinking', 'chunk_size', 'concurrent', 'temperature', 'thinking', 'chunk_size', 'concurrent',
'insert_mode', 'separator', 'glossary_dict' 'insert_mode', 'separator', 'glossary_dict'
}, exclude_none=True) }, exclude_none=True)
) translator_args['glossary_generate_enable'] = payload.glossary_generate_enable
translator_args['glossary_agent_config'] = build_glossary_agent_config()
translator_config = HtmlTranslatorConfig(**translator_args)
workflow_config = HtmlWorkflowConfig( workflow_config = HtmlWorkflowConfig(
translator_config=translator_config, translator_config=translator_config,
logger=task_logger logger=task_logger
+5
View File
@@ -8,9 +8,14 @@ class Glossary:
self.glossary_dict[src]=dst self.glossary_dict[src]=dst
def append_system_prompt(self,text:str): def append_system_prompt(self,text:str):
flag=False
prompt="\n以下为参考术语表:\n" prompt="\n以下为参考术语表:\n"
for src,dst in self.glossary_dict.items(): for src,dst in self.glossary_dict.items():
if src in text: if src in text:
prompt+=f"{src}=>{dst}\n" prompt+=f"{src}=>{dst}\n"
flag=True
prompt+="术语表结束\n" prompt+="术语表结束\n"
if flag:
return prompt return prompt
else:
return ""
+80 -70
View File
@@ -18,16 +18,16 @@
"insertModeAppend": "附加到原文后 (Append)", "insertModeAppend": "附加到原文后 (Append)",
"insertModePrepend": "附加到原文前 (Prepend)", "insertModePrepend": "附加到原文前 (Prepend)",
"insertModeHelpDocx": "选择如何将翻译后的文本插入。", "insertModeHelpDocx": "选择如何将翻译后的文本插入。",
"separatorLabel": "分隔符",
"separatorPlaceholder": "例如: \\n---翻译---\\n",
"separatorHelp": "当插入模式为附加或前置时,用于分隔原文和译文的字符。<code>\\n</code> 代表换行。",
"insertModeHelpXlsx": "选择如何将翻译后的文本插入到单元格中。", "insertModeHelpXlsx": "选择如何将翻译后的文本插入到单元格中。",
"separatorPlaceholderSimple": "例如: \\n---\\n",
"xlsxTranslateRegionsLabel": "翻译区域 (可选)",
"xlsxTranslateRegionsPlaceholder": "每行一个区域, 例如:Sheet1!A1:B10(不指定表名则对所有表生效)",
"insertModeHelpSrt": "选择如何将翻译后的文本插入。", "insertModeHelpSrt": "选择如何将翻译后的文本插入。",
"insertModeHelpEpub": "选择如何将翻译后的文本插入。", "insertModeHelpEpub": "选择如何将翻译后的文本插入。",
"insertModeHelpHtml": "选择如何将翻译后的文本插入。", "insertModeHelpHtml": "选择如何将翻译后的文本插入。",
"separatorLabel": "分隔符",
"separatorPlaceholder": "例如: \\n---翻译---\\n",
"separatorPlaceholderSimple": "例如: \\n---\\n",
"separatorHelp": "当插入模式为附加或前置时,用于分隔原文和译文的字符。<code>\\n</code> 代表换行。",
"xlsxTranslateRegionsLabel": "翻译区域 (可选)",
"xlsxTranslateRegionsPlaceholder": "每行一个区域, 例如:Sheet1!A1:B10(不指定表名则对所有表生效)",
"jsonPathLabel": "需要翻译的JSON路径", "jsonPathLabel": "需要翻译的JSON路径",
"jsonPathPlaceholder": "每行一个路径, 例如:\n$.name\n$.*", "jsonPathPlaceholder": "每行一个路径, 例如:\n$.name\n$.*",
"jsonPathHelp": "采用<code>jsonpath-ng</code>的路径选择语法,每一行表示一个json路径", "jsonPathHelp": "采用<code>jsonpath-ng</code>的路径选择语法,每一行表示一个json路径",
@@ -63,8 +63,13 @@
"glossaryHelp": "选择一个或多个CSV文件。文件需包含'src'和'dst'两列标题,分别代表原文和译文。", "glossaryHelp": "选择一个或多个CSV文件。文件需包含'src'和'dst'两列标题,分别代表原文和译文。",
"viewGlossaryBtn": "查看术语表", "viewGlossaryBtn": "查看术语表",
"clearGlossaryBtn": "清空", "clearGlossaryBtn": "清空",
"chunkSizeLabel": "分块大小", "glossaryGenTitle": "术语表",
"glossaryGenEnableLabel": "自动生成术语表",
"glossaryGenConfigLabel": "生成术语表配置",
"glossaryGenConfigSame": "与翻译配置相同",
"glossaryGenConfigCustom": "自定义",
"resetBtn": "重置", "resetBtn": "重置",
"chunkSizeLabel": "分块大小",
"concurrentLabel": "并发数", "concurrentLabel": "并发数",
"githubInfo": "GitHub主页(欢迎star❤): <br/><a href=\"https://github.com/xunbu/docutranslate\" target=\"_blank\" rel=\"noopener noreferrer\">https://github.com/xunbu/docutranslate</a>", "githubInfo": "GitHub主页(欢迎star❤): <br/><a href=\"https://github.com/xunbu/docutranslate\" target=\"_blank\" rel=\"noopener noreferrer\">https://github.com/xunbu/docutranslate</a>",
"qqGroupInfo": "交流QQ群: 1047781902", "qqGroupInfo": "交流QQ群: 1047781902",
@@ -75,7 +80,7 @@
"taskCardIdPlaceholder": "等待提交...", "taskCardIdPlaceholder": "等待提交...",
"taskCardFileDrop": "点击或拖拽文件到此处", "taskCardFileDrop": "点击或拖拽文件到此处",
"taskCardFileSelected": "文件已选择", "taskCardFileSelected": "文件已选择",
"taskCardFilenameLabel": "文件名: ", "taskCardFilenameLabel": "文件名:",
"taskCardLogLabel": "日志", "taskCardLogLabel": "日志",
"taskCardStatusWaiting": "等待上传文件...", "taskCardStatusWaiting": "等待上传文件...",
"taskCardPreviewBtn": "预览", "taskCardPreviewBtn": "预览",
@@ -117,43 +122,43 @@
"aiSettingsTitleText": "翻译模型", "aiSettingsTitleText": "翻译模型",
"translationSettingsTitleText": "翻译配置", "translationSettingsTitleText": "翻译配置",
"advancedSettingsTitleText": "高级参数", "advancedSettingsTitleText": "高级参数",
"engineOptionIdentity": "不转换(仅复制)", "engineOptionIdentity": "不转换(Identity)",
"engineOptionMineru": "Mineru", "engineOptionMineru": "Mineru",
"engineOptionDocling": "Docling", "engineOptionDocling": "Docling",
"status_selectFileFirst": "请先选择文件!", "status_selectFileFirst": "请先选择文件!",
"status_invalidWorkflow": "无效的工作流选择。", "status_fillRequired": "请填写所有必填项!",
"status_fillRequired": "请填写所有必填项。", "status_invalidWorkflow": "选择了无效的工作流。",
"status_releasingOldTask": "正在释放旧任务...", "status_releasingOldTask": "正在释放旧任务资源...",
"btn_initializing": "初始化...", "btn_initializing": "初始化...",
"status_encodingAndSubmitting": "正在编码并提交文件...", "status_encodingAndSubmitting": "正在编码文件并提交任务...",
"status_requestOk": "请求成功,任务已开始。", "status_requestOk": "任务请求成功,等待处理...",
"btn_cancelTranslation": "取消翻译", "btn_cancelTranslation": "取消翻译",
"status_requestFail": "请求失败", "status_requestFail": "请求失败",
"status_initFail": "初始化失败", "status_initFail": "任务启动失败",
"status_cancelling": "取消中...", "status_cancelling": "取消中...",
"status_cancelSent": "取消请求已发送。", "status_cancelSent": "取消请求已发送。",
"status_cancelFail": "取消失败", "status_cancelFail": "取消失败",
"status_gettingStatus": "正在获取状态...", "status_gettingStatus": "正在获取状态...",
"btn_reTranslate": "重新翻译", "btn_reTranslate": "重新翻译",
"status_updateError": "状态更新失败。", "status_updateError": "状态更新失败。",
"preview_loading": "加载预览中...", "preview_loading": "正在加载预览...",
"preview_cantReadOriginal": "无法读取原文文件内容。", "preview_cantReadOriginal": "无法读取原文内容。",
"preview_cantPreviewType": "无法预览此文件类型", "preview_cantPreviewType": "无法预览此文件类型",
"preview_noOriginalCache": "无原文文件缓存可供预览。", "preview_noOriginalCache": "无原文缓存,请重新上传文件以预览。",
"preview_loadFailed": "预览加载失败。", "preview_loadFailed": "加载预览失败。",
"pdf_preparing": "正在准备PDF...", "pdf_preparing": "正在准备PDF...",
"pdf_print_failed": "调用打印功能失败。请尝试手动保存为PDF。", "pdf_print_failed": "打印/另存为PDF失败。可能是浏览器限制或预览内容问题。",
"pdf_fetch_failed": "获取译文内容失败,无法生成PDF。", "pdf_fetch_failed": "获取预览内容失败,无法生成PDF。",
"preview_bilingual": "双语预览", "preview_bilingual": "双语预览",
"preview_translatedOnly": "仅译文预览", "preview_translatedOnly": "仅译文预览",
"admin_tasklist_failed": "管理员模式:获取服务器任务列表失败。" "admin_tasklist_failed": "管理员模式:无法从服务器加载任务列表。"
}, },
"en": { "en": {
"pageTitle": "DocuTranslate - Interactive Document Translation", "pageTitle": "DocuTranslate - Interactive Document Translation",
"tutorialBtn": "Tutorial", "tutorialBtn": "Tutorial",
"projectContributeBtn": "Contribute", "projectContributeBtn": "Contribute",
"workflowTitle": "1. Select Workflow", "workflowTitle": "1. Select Workflow",
"workflowOptionMarkdown": "Markdown-based Translation (.pdf/.md/.png, etc.)", "workflowOptionMarkdown": "Translate via Markdown (.pdf/.md/.png, etc.)",
"workflowOptionTxt": "Plain Text Translation (.txt)", "workflowOptionTxt": "Plain Text Translation (.txt)",
"workflowOptionJson": "JSON Translation (.json)", "workflowOptionJson": "JSON Translation (.json)",
"workflowOptionDocx": "DOCX Translation (.docx)", "workflowOptionDocx": "DOCX Translation (.docx)",
@@ -163,31 +168,31 @@
"workflowOptionHtml": "HTML Translation (.html)", "workflowOptionHtml": "HTML Translation (.html)",
"autoWorkflowLabel": "Auto-select workflow", "autoWorkflowLabel": "Auto-select workflow",
"insertModeLabel": "Insert Mode", "insertModeLabel": "Insert Mode",
"insertModeReplace": "Replace Original Text", "insertModeReplace": "Replace Original",
"insertModeAppend": "Append to Original Text", "insertModeAppend": "Append to Original",
"insertModePrepend": "Prepend to Original Text", "insertModePrepend": "Prepend to Original",
"insertModeHelpDocx": "Choose how to insert the translated text.", "insertModeHelpDocx": "Choose how the translated text is inserted.",
"insertModeHelpXlsx": "Choose how the translated text is inserted into cells.",
"insertModeHelpSrt": "Choose how the translated text is inserted.",
"insertModeHelpEpub": "Choose how the translated text is inserted.",
"insertModeHelpHtml": "Choose how the translated text is inserted.",
"separatorLabel": "Separator", "separatorLabel": "Separator",
"separatorPlaceholder": "e.g., \\n---translation---\\n", "separatorPlaceholder": "e.g., \\n---Translation---\\n",
"separatorHelp": "Characters used to separate original and translated text in append/prepend modes. <code>\\n</code> represents a new line.",
"insertModeHelpXlsx": "Choose how to insert translated text into cells.",
"separatorPlaceholderSimple": "e.g., \\n---\\n", "separatorPlaceholderSimple": "e.g., \\n---\\n",
"separatorHelp": "Characters used to separate original and translated text in 'Append' or 'Prepend' mode. <code>\\n</code> represents a newline.",
"xlsxTranslateRegionsLabel": "Translate Regions (Optional)", "xlsxTranslateRegionsLabel": "Translate Regions (Optional)",
"xlsxTranslateRegionsPlaceholder": "One region per line, e.g., Sheet1!A1:B10 (applies to all sheets if sheet name is omitted)", "xlsxTranslateRegionsPlaceholder": "One region per line, e.g., Sheet1!A1:B10 (applies to all sheets if sheet name is omitted)",
"insertModeHelpSrt": "Choose how to insert the translated text.",
"insertModeHelpEpub": "Choose how to insert the translated text.",
"insertModeHelpHtml": "Choose how to insert the translated text.",
"jsonPathLabel": "JSON Paths to Translate", "jsonPathLabel": "JSON Paths to Translate",
"jsonPathPlaceholder": "One path per line, e.g.:\n$.name\n$.*", "jsonPathPlaceholder": "One path per line, e.g.:\n$.name\n$.*",
"jsonPathHelp": "Uses <code>jsonpath-ng</code> syntax. One JSON path per line.", "jsonPathHelp": "Uses <code>jsonpath-ng</code> syntax. Each line represents a JSON path.",
"parsingEngineLabel": "Parsing Engine", "parsingEngineLabel": "Parsing Engine",
"parsingEngineHelp": "Optional if the uploaded file is already in .md format.", "parsingEngineHelp": "If the uploaded file is already in .md format, this can be left unselected.",
"getMineruTokenTitle": "Get Mineru Token", "getMineruTokenTitle": "Get Mineru Token",
"mineruTokenPlaceholder": "Required when using the Mineru engine", "mineruTokenPlaceholder": "Required when using the Mineru engine",
"modelVersionLabel": "Mineru Model Version", "modelVersionLabel": "Mineru Model Version",
"modelVersionVlm": "VLM", "modelVersionVlm": "VLM",
"modelVersionPipline": "Pipeline", "modelVersionPipline": "Pipeline",
"modelVersionHelp": "Mineru VLM is a newer, internal test model.", "modelVersionHelp": "Mineru VLM is a newer, internal beta model.",
"formulaOcrLabel": "Formula Recognition", "formulaOcrLabel": "Formula Recognition",
"codeOcrLabel": "Code Recognition", "codeOcrLabel": "Code Recognition",
"platformLabel": "Select Platform", "platformLabel": "Select Platform",
@@ -197,40 +202,45 @@
"getApiKeyTitle": "Get API Key", "getApiKeyTitle": "Get API Key",
"apiKeyPlaceholder": "Please enter your API Key", "apiKeyPlaceholder": "Please enter your API Key",
"modelIdLabel": "Model ID", "modelIdLabel": "Model ID",
"modelIdPlaceholder": "e.g., gpt-4o, glm-4", "modelIdPlaceholder": "e.g., gpt-4o, llama-3-70b",
"targetLanguageLabel": "Target Language", "targetLanguageLabel": "Target Language",
"targetLanguageCustom": "Other (Custom)", "targetLanguageCustom": "Other (Custom)",
"customLangPlaceholder": "Enter target language, e.g., Italian", "customLangPlaceholder": "Enter target language, e.g., Italian",
"thinkingModeLabel": "Thinking Mode", "thinkingModeLabel": "Thinking Mode",
"thinkingModeTooltip": "Set the thinking mode for hybrid inference models, currently supporting Zhipu's glm-4.5 series, Alibaba Cloud's qwen3 series, Volcengine's Doubao-Seed-1.6 series, etc.", "thinkingModeTooltip": "Sets the thinking mode for hybrid inference models, currently supporting Zhipu's glm-4.5 series, Alibaba Cloud's qwen3 series, Volcengine's Doubao-Seed-1.6 series, etc.",
"thinkingModeEnable": "Enable", "thinkingModeEnable": "Enable",
"thinkingModeDisable": "Disable", "thinkingModeDisable": "Disable",
"thinkingModeDefault": "Default", "thinkingModeDefault": "Default",
"customPromptLabel": "Custom Prompt", "customPromptLabel": "Custom Prompt",
"customPromptPlaceholder": "Optional, e.g., 'Keep proper nouns in their original form'", "customPromptPlaceholder": "Optional, e.g., 'Do not translate proper names'",
"glossaryLabel": "Glossary (Optional)", "glossaryLabel": "Glossary (Optional)",
"glossaryHelp": "Select one or more CSV files. Files must contain 'src' and 'dst' headers for source and destination terms.", "glossaryHelp": "Select one or more CSV files. Files must contain 'src' and 'dst' headers for source and destination terms.",
"viewGlossaryBtn": "View Glossary", "viewGlossaryBtn": "View Glossary",
"clearGlossaryBtn": "Clear", "clearGlossaryBtn": "Clear",
"chunkSizeLabel": "Chunk Size", "glossaryGenTitle": "Glossary",
"glossaryGenEnableLabel": "Auto-generate Glossary",
"glossaryGenConfigLabel": "Glossary Generation Config",
"glossaryGenConfigSame": "Same as Translator",
"glossaryGenConfigCustom": "Custom",
"resetBtn": "Reset", "resetBtn": "Reset",
"chunkSizeLabel": "Chunk Size",
"concurrentLabel": "Concurrency", "concurrentLabel": "Concurrency",
"githubInfo": "GitHub (star us ❤): <br/><a href=\"https://github.com/xunbu/docutranslate\" target=\"_blank\" rel=\"noopener noreferrer\">https://github.com/xunbu/docutranslate</a>", "githubInfo": "GitHub Repo (Star us! ❤): <br/><a href=\"https://github.com/xunbu/docutranslate\" target=\"_blank\" rel=\"noopener noreferrer\">https://github.com/xunbu/docutranslate</a>",
"qqGroupInfo": "QQ Group: 1047781902", "qqGroupInfo": "QQ Group for discussions: 1047781902",
"taskListTitle": "Task List", "taskListTitle": "Task List",
"newTaskBtn": "New Task", "newTaskBtn": "New Task",
"noTaskPlaceholder": "No tasks yet. Click 'New Task' to get started!", "noTaskPlaceholder": "No tasks yet. Click 'New Task' to get started!",
"taskCardIdLabel": "Task ID", "taskCardIdLabel": "Task ID",
"taskCardIdPlaceholder": "Waiting for submission...", "taskCardIdPlaceholder": "Awaiting submission...",
"taskCardFileDrop": "Click or drag file here", "taskCardFileDrop": "Click or drag file here",
"taskCardFileSelected": "File Selected", "taskCardFileSelected": "File selected",
"taskCardFilenameLabel": "Filename: ", "taskCardFilenameLabel": "Filename:",
"taskCardLogLabel": "Log", "taskCardLogLabel": "Log",
"taskCardStatusWaiting": "Waiting for file upload...", "taskCardStatusWaiting": "Waiting for file upload...",
"taskCardPreviewBtn": "Preview", "taskCardPreviewBtn": "Preview",
"taskCardDownloadBtn": "Download", "taskCardDownloadBtn": "Download",
"taskCardStartBtn": "Start Translation", "taskCardStartBtn": "Start Translation",
"downloadMdEmbedded": "Markdown (Embedded Images)", "downloadMdEmbedded": "Markdown (Embedded Imgs)",
"downloadMdZip": "Markdown (.zip)", "downloadMdZip": "Markdown (.zip)",
"previewTitle": "Preview", "previewTitle": "Preview",
"previewBilingualBtn": "Bilingual", "previewBilingualBtn": "Bilingual",
@@ -240,61 +250,61 @@
"closeBtn": "Close", "closeBtn": "Close",
"downloadBtn": "Download", "downloadBtn": "Download",
"tutorialModalTitle": "User Guide", "tutorialModalTitle": "User Guide",
"tutorialModalBody": "<p><i class=\"bi bi-camera-video me-2\"></i>Video tutorials can be found by searching for <a href=\"https://search.bilibili.com/all?keyword=docutranslate\" target=\"_blank\">docutranslate</a> on Bilibili.</p><p>Welcome to DocuTranslate! Please follow these steps to translate your documents:</p><ol><li><strong><i class=\"bi bi-diagram-3 me-2\"></i>Select a Workflow</strong><p class=\"mt-2\">First, choose the appropriate translation process from the top of the settings panel. Different workflows are suited for different file types:<ul><li><b>Markdown-based Translation</b>: Ideal for translating PDFs, markdown files, images, etc.</li><li><b>Plain Text Translation</b>: For translating <code>.txt</code> and other plain text files.</li><li><b>JSON Translation</b>: For translating specific fields within <code>.json</code> files.</li><li><b>DOCX Translation</b>: For translating <code>.docx</code> files.</li><li><b>XLSX Translation</b>: For translating <code>.xlsx</code> spreadsheets and <code>.csv</code> files.</li><li><b>SRT Subtitle Translation</b>: For translating <code>.srt</code> subtitle files.</li><li><b>EPUB Translation</b>: For translating <code>.epub</code> e-book files.</li><li><b>HTML Translation</b>: For translating <code>.html</code> files.</li></ul><div class=\"alert alert-info mt-2\" role=\"alert\"><i class=\"bi bi-lightbulb-fill me-2\"></i>New Feature: The \"Auto-select workflow\" switch is now enabled by default. Simply upload your file, and the system will automatically match it with the correct workflow to simplify the process.</div></p></li><li><strong><i class=\"bi bi-gear-fill me-2\"></i>Configure Parameters</strong><p class=\"mt-2\">Based on your chosen workflow, complete the necessary configurations. All settings are automatically saved in your browser.</p><ul><li class=\"mb-2\"><strong>Parsing Settings</strong> (Only shown for the \"Markdown-based Translation\" workflow):<ul class=\"mt-1\"><li><strong>Parsing Engine</strong>: Select an engine to convert your file (like a PDF) into a translation-friendly Markdown format. This is not required if your file is already in Markdown format.</li><li><strong>Mineru Token</strong>: If you choose the <code>minerU</code> engine, you must enter your token here.</li></ul></li><li class=\"mb-2\"><strong>DOCX/XLSX/SRT/EPUB/HTML Translation Options</strong> (Shown for corresponding workflows):<ul class=\"mt-1\"><li><strong>Insert Mode</strong>: Defines how the translation is placed in the document or subtitle. You can choose to \"Replace\" the original, \"Append\" after it, or \"Prepend\" before it.</li><li><strong>Separator</strong>: When using \"Append\" or \"Prepend\" mode, this is used to insert a separator between the original and translated text.</li></ul></li><li class=\"mb-2\"><strong>JSON Path Settings</strong> (Only shown for the \"JSON Translation\" workflow):<ul class=\"mt-1\"><li><strong>JSON Paths to Translate</strong>: Enter one <a href=\"https://goessner.net/articles/JsonPath/\" target=\"_blank\">JSONPath</a> expression per line to specify the fields to be translated.</li><li>For example: <code>$..description</code> translates all values for the key 'description'. <code>$.items[0].name</code> translates the 'name' value of the first item.</li></ul></li><li class=\"mb-2\"><strong>Translation Model</strong>:<ul class=\"mt-1\"><li><strong>Select Platform / API Base URL / API Key / Model ID</strong>: Configure the AI translation service you wish to use.</li><li>Refer to the platform's documentation for the model ID. It is recommended to use non-inference models or hybrid inference models (with thinking mode disabled).</li></ul></li><li class=\"mb-2\"><strong>Translation Settings</strong>:<ul class=\"mt-1\"><li><strong>Target Language / Custom Prompt / Glossary</strong>: Specify the target language for the translation, add any extra instructions, and provide a glossary to ensure the accuracy of specific terms.</li><li><strong>Thinking Mode</strong>: Sets whether a hybrid inference model should \"think\". Currently supports Zhipu's glm4.5 series, Alibaba Cloud's qwen3 series, and Volcengine's seed1.6 series. Disabling thinking is recommended.</li></ul></li><li class=\"mb-2\"><strong>Advanced Parameters</strong>:<ul class=\"mt-1\"><li><strong>Chunk Size / Concurrency / Temperature</strong>: The size of text chunks sent to the AI, the number of concurrent requests, and the temperature. The default values are usually sufficient.</li></ul></li></ul></li><li><strong><i class=\"bi bi-file-earmark-arrow-up-fill me-2\"></i>Upload File</strong><p class=\"mt-2\">In the task list on the right, click or drag your document into the file upload area.</p></li><li><strong><i class=\"bi bi-play-circle-fill me-2\"></i>Start Translation</strong><p class=\"mt-2\">Once the file is selected, click the <span class=\"badge bg-primary\">Start Translation</span> button on the task card. The system will begin processing the task, and you can moniLine truncated "tutorialModalBody": "<p><i class=\"bi bi-camera-video me-2\"></i>Video tutorials are available on Bilibili by searching for <a href=\"https://search.bilibili.com/all?keyword=docutranslate\" target=\"_blank\">docutranslate</a>.</p><p>Welcome to DocuTranslate! Follow these steps to translate your documents:</p><ol><li><strong><i class=\"bi bi-diagram-3 me-2\"></i>Select Workflow</strong><p class=\"mt-2\">First, choose your desired translation process from the top of the settings panel. Different workflows are suited for different file types:<ul><li><b>Translate via Markdown</b>: Ideal for translating PDF, Markdown, images, etc.</li><li><b>Plain Text Translation</b>: For <code>.txt</code> and other plain text files.</li><li><b>JSON Translation</b>: For translating specific fields in <code>.json</code> files.</li><li><b>DOCX Translation</b>: For translating <code>.docx</code> files.</li><li><b>XLSX Translation</b>: For translating <code>.xlsx</code> spreadsheets and <code>.csv</code> files.</li><li><b>SRT Subtitle Translation</b>: For translating <code>.srt</code> subtitle files.</li><li><b>EPUB Translation</b>: For translating <code>.epub</code> e-book files.</li><li><b>HTML Translation</b>: For translating <code>.html</code> files.</li></ul><div class=\"alert alert-info mt-2\" role=\"alert\"><i class=\"bi bi-lightbulb-fill me-2\"></i>New Feature: The 'Auto-select workflow' switch is now on by default. Just upload your file, and the system will automatically match it to the appropriate workflow for you.</div></p></li><li><strong><i class=\"bi bi-gear-fill me-2\"></i>Configure Parameters</strong><p class=\"mt-2\">Configure the settings based on your chosen workflow. All settings are automatically saved in your browser.</p><ul><li class=\"mb-2\"><strong>Parsing Config</strong> (only for 'Translate via Markdown' workflow):<ul class=\"mt-1\"><li><strong>Parsing Engine</strong>: Choose an engine to convert your file (like a PDF) into a translation-friendly Markdown format. No selection is needed if your file is already Markdown.</li><li><strong>Mineru Token</strong>: If you select the <code>minerU</code> engine, you must enter your token here.</li></ul></li><li class=\"mb-2\"><strong>DOCX/XLSX/SRT/EPUB/HTML Options</strong> (for their respective workflows):<ul class=\"mt-1\"><li><strong>Insert Mode</strong>: Define how the translation result is placed in the document. You can 'Replace' the original, 'Append' after it, or 'Prepend' before it.</li><li><strong>Separator</strong>: When using 'Append' or 'Prepend', this is used to insert a separator between the original and translated text.</li></ul></li><li class=\"mb-2\"><strong>JSON Path Config</strong> (only for 'JSON Translation' workflow):<ul class=\"mt-1\"><li><strong>JSON Paths to Translate</strong>: Enter one <a href=\"https://goessner.net/articles/JsonPath/\" target=\"_blank\">JSONPath</a> expression per line to specify which fields to translate.</li><li>Example: <code>$..description</code> translates all values with the key 'description'. <code>$.items[0].name</code> translates the 'name' of the first item.</li></ul></li><li class=\"mb-2\"><strong>Translation Model</strong>:<ul class=\"mt-1\"><li><strong>Platform/API Base URL/API Key/Model ID</strong>: Configure the AI translation service you want to use.</li><li>Refer to the platform's documentation for model IDs. It's recommended to use non-inference or hybrid models (with thinking disabled).</li></ul></li><li class=\"mb-2\"><strong>Translation Config</strong>:<ul class=\"mt-1\"><li><strong>Target Language/Custom Prompt/Glossary</strong>: Specify the target language, add extra instructions, and provide a glossary to ensure term accuracy.</li><li><strong>Thinking Mode</strong>: Set whether a hybrid inference model should 'think'. Supported models include Zhipu's glm4.5 series, Alibaba's qwen3 series, and Volcengine's seed1.6 series. Disabling thinking is recommended.</li></ul></li><li class=\"mb-2\"><strong>Advanced Parameters</strong>:<ul class=\"mt-1\"><li><strong>Chunk Size/Concurrency/Temperature</strong>: The size of text chunks sent to the AI, the number of concurrent requests, and the temperature. Defaults are usually fine.</li></ul></li></ul></li><li><strong><i class=\"bi bi-file-earmark-arrow-up-fill me-2\"></i>Upload File</strong><p class=\"mt-2\">In the task list on the right, click or drag your document into the file upload area.</p></li><li><strong><i class=\"bi bi-play-circle-fill me-2\"></i>Start Translation</strong><p class=\"mt-2\">Once the file is selected, click the <span class=\"badge bg-primary\">Start Translation</span> button on the task card. The system will begin processing, and you can monitor real-time progress in the log area.</p></li><li><strong><i class=\"bi bi-check-circle-fill me-2\"></i>View & Download</strong><p class=\"mt-2\">After the translation is complete, action buttons will appear on the task card:</p><ul><li><span class=\"badge bg-success\"><i class=\"bi bi-eyeLine truncated
"tutorialUnderstandBtn": "Got it", "tutorialUnderstandBtn": "I understand",
"contributorsModalTitle": "Thanks for Contributing", "contributorsModalTitle": "Thanks for Contributing!",
"contributorsPara1": "DocuTranslate is an open-source project! The needs and usage of the community drive its progress.", "contributorsPara1": "DocuTranslate is an open-source project! The community's needs and usage are what drive the project forward.",
"contributorsPara2": "A heartfelt thank you to all friends who have sponsored the project, submitted code, provided valuable suggestions, and starred the project!", "contributorsPara2": "A heartfelt thank you to everyone who has funded the project, submitted code, provided valuable suggestions, and starred the repository!",
"contributorsWelcome": "You are welcome to contribute in the following ways:", "contributorsWelcome": "You're welcome to contribute in the following ways:",
"contributorsGithub": "GitHub Page", "contributorsGithub": "GitHub Repo",
"contributorsPR": "Submit a Pull Request", "contributorsPR": "Submit a Pull Request",
"contributorsIssue": "Report an Issue", "contributorsIssue": "Report an Issue",
"contributorsQQ": "Or contact the author via QQ group: <span>1047781902</span>", "contributorsQQ": "Or contact the author via QQ Group: <span>1047781902</span>",
"glossaryModalTitle": "Current Glossary", "glossaryModalTitle": "Current Glossary",
"glossaryTableSource": "Source (src)", "glossaryTableSource": "Source (src)",
"glossaryTableDestination": "Destination (dst)", "glossaryTableDestination": "Destination (dst)",
"init_i18n_failed_alert": "Failed to load interface translations. Please check your network connection or contact an administrator.", "init_i18n_failed_alert": "Failed to load interface translations. Please check your network connection or contact an administrator.",
"init_failed_alert": "Initialization failed, could not connect to the backend service. Please ensure the service is running and refresh the page.", "init_failed_alert": "Initialization failed, could not connect to the backend service. Please ensure the service is running and refresh the page.",
"glossaryEmpty": "Glossary is empty.", "glossaryEmpty": "The glossary is empty.",
"parsingSettingsTitleText": "Parsing Settings", "parsingSettingsTitleText": "Parsing Config",
"jsonSettingsTitleText": "JSON Path Settings", "jsonSettingsTitleText": "JSON Path Config",
"xlsxSettingsTitleText": "XLSX Translation Options", "xlsxSettingsTitleText": "XLSX Translation Options",
"docxSettingsTitleText": "DOCX Translation Options", "docxSettingsTitleText": "DOCX Translation Options",
"srtSettingsTitleText": "SRT Translation Options", "srtSettingsTitleText": "SRT Translation Options",
"epubSettingsTitleText": "EPUB Translation Options", "epubSettingsTitleText": "EPUB Translation Options",
"htmlSettingsTitleText": "HTML Translation Options", "htmlSettingsTitleText": "HTML Translation Options",
"aiSettingsTitleText": "Translation Model", "aiSettingsTitleText": "Translation Model",
"translationSettingsTitleText": "Translation Settings", "translationSettingsTitleText": "Translation Config",
"advancedSettingsTitleText": "Advanced Parameters", "advancedSettingsTitleText": "Advanced Parameters",
"engineOptionIdentity": "Identity (Copy only)", "engineOptionIdentity": "No Conversion (Identity)",
"engineOptionMineru": "Mineru", "engineOptionMineru": "Mineru",
"engineOptionDocling": "Docling", "engineOptionDocling": "Docling",
"status_selectFileFirst": "Please select a file first!", "status_selectFileFirst": "Please select a file first!",
"status_fillRequired": "Please fill in all required fields!",
"status_invalidWorkflow": "Invalid workflow selected.", "status_invalidWorkflow": "Invalid workflow selected.",
"status_fillRequired": "Please fill in all required fields.", "status_releasingOldTask": "Releasing old task resources...",
"status_releasingOldTask": "Releasing old task...",
"btn_initializing": "Initializing...", "btn_initializing": "Initializing...",
"status_encodingAndSubmitting": "Encoding and submitting file...", "status_encodingAndSubmitting": "Encoding file and submitting task...",
"status_requestOk": "Request successful, task started.", "status_requestOk": "Task submitted successfully, awaiting processing...",
"btn_cancelTranslation": "Cancel Translation", "btn_cancelTranslation": "Cancel Translation",
"status_requestFail": "Request failed", "status_requestFail": "Request failed",
"status_initFail": "Initialization failed", "status_initFail": "Failed to start task",
"status_cancelling": "Cancelling...", "status_cancelling": "Cancelling...",
"status_cancelSent": "Cancellation request sent.", "status_cancelSent": "Cancellation request sent.",
"status_cancelFail": "Cancellation failed", "status_cancelFail": "Cancellation failed",
"status_gettingStatus": "Getting status...", "status_gettingStatus": "Getting status...",
"btn_reTranslate": "Re-translate", "btn_reTranslate": "Re-translate",
"status_updateError": "Status update failed.", "status_updateError": "Failed to update status.",
"preview_loading": "Loading preview...", "preview_loading": "Loading preview...",
"preview_cantReadOriginal": "Cannot read original file content.", "preview_cantReadOriginal": "Could not read original file content.",
"preview_cantPreviewType": "Cannot preview this file type", "preview_cantPreviewType": "Cannot preview this file type",
"preview_noOriginalCache": "No original file cached for preview.", "preview_noOriginalCache": "No original file cached. Please re-upload to preview.",
"preview_loadFailed": "Failed to load preview.", "preview_loadFailed": "Failed to load preview.",
"pdf_preparing": "Preparing PDF...", "pdf_preparing": "Preparing PDF...",
"pdf_print_failed": "Failed to invoke print function. Please try saving to PDF manually.", "pdf_print_failed": "Print/Save as PDF failed. This may be due to browser restrictions or preview content issues.",
"pdf_fetch_failed": "Failed to fetch translated content, cannot generate PDF.", "pdf_fetch_failed": "Failed to fetch preview content, cannot generate PDF.",
"preview_bilingual": "Bilingual Preview", "preview_bilingual": "Bilingual Preview",
"preview_translatedOnly": "Translated Only Preview", "preview_translatedOnly": "Translated Only Preview",
"admin_tasklist_failed": "Admin Mode: Failed to get task list from server." "admin_tasklist_failed": "Admin mode: Failed to load task list from server."
} }
} }
+1 -1
View File
@@ -1 +1 @@
<!DOCTYPE html> <html lang="zh-CN" data-bs-theme="auto"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title data-i18n-title="pageTitle">DocuTranslate - 交互式文档翻译</title> <link rel="icon" href="/static/favicon.ico" type="image/x-icon"> <!-- Bootstrap CSS --> <link href="/static/bootstrap.css" rel="stylesheet" crossorigin="anonymous"> <!-- Bootstrap Icons --> <link rel="stylesheet" href="/static/bootstrap-icons.css"> <style> body { background-color: var(--bs-body-bg); } .main-container { display: flex; flex-direction: column; height: 100vh; padding-top: 1rem; padding-bottom: 1rem; } .settings-panel { height: calc(100vh - 2rem); overflow-y: auto; padding-right: 15px; /* for scrollbar */ } .task-area { height: calc(100vh - 2rem); overflow-y: auto; } .task-card { transition: all 0.3s ease-in-out; } .task-id-placeholder { color: var(--bs-secondary-color); font-style: italic; } .log-area { height: 150px; background-color: var(--bs-tertiary-bg); border: 1px solid var(--bs-border-color); border-radius: .375rem; font-family: monospace; font-size: 0.8rem; padding: 10px; overflow-y: auto; white-space: pre-wrap; word-break: break-all; } .file-drop-area { border: 2px dashed var(--bs-secondary-bg); border-radius: .375rem; padding: 2rem; text-align: center; cursor: pointer; transition: all 0.2s ease-in-out; background-color: var(--bs-body-bg); } .file-drop-area.drag-over { border-color: var(--bs-primary); background-color: var(--bs-secondary-bg); } .file-drop-area.file-selected { border-style: solid; border-color: var(--bs-success); background-color: var(--bs-success-bg-subtle); } .file-drop-area.input-error { border-color: var(--bs-danger); } .file-name-display.input-error-text { color: var(--bs-danger); font-weight: bold; } #printFrame, #translatedPreviewFrame { border: none; width: 100%; } #previewOffcanvas { --bs-offcanvas-width: 95vw; max-width: 1600px; } .preview-split-container { display: flex; flex-direction: row; height: 90%; } .preview-pane-wrapper { display: flex; flex-direction: column; overflow: hidden; /* Important for split.js */ } .preview-pane-wrapper h6 { flex-shrink: 0; padding: 0.25rem; } .preview-pane-wrapper .preview-pane { flex-grow: 1; /* Make the inner pane grow */ border: 1px solid var(--bs-border-color); border-radius: .375rem; overflow: auto; } .gutter { background-color: var(--bs-tertiary-bg); background-repeat: no-repeat; background-position: 50%; } .gutter.gutter-horizontal { cursor: col-resize; border-left: 1px solid var(--bs-border-color); border-right: 1px solid var(--bs-border-color); } .gutter.gutter-vertical { cursor: row-resize; border-top: 1px solid var(--bs-border-color); border-bottom: 1px solid var(--bs-border-color); } .preview-pane iframe, .preview-pane pre { width: 100%; height: 95%; border: none; margin: 0; padding: 0; overflow: auto; background-color: var(--bs-body-bg); } .slider-reset-btn { visibility: hidden; } .bottom-left-controls { position: fixed; bottom: 1rem; left: 1rem; z-index: 1050; display: flex; gap: 0.5rem; } @media (max-width: 991.98px) { .main-container { height: auto; padding-bottom: 6rem; } .settings-panel, .task-area { height: auto; overflow-y: visible; } .settings-panel { padding-right: 0; margin-bottom: 2rem; } } @media (max-width: 767.98px) { .task-card .col-md-7 { margin-top: 1.5rem; } Line truncated <!DOCTYPE html> <html lang="zh-CN" data-bs-theme="auto"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title data-i18n-title="pageTitle">DocuTranslate - 交互式文档翻译</title> <link rel="icon" href="/static/favicon.ico" type="image/x-icon"> <!-- Bootstrap CSS --> <link href="/static/bootstrap.css" rel="stylesheet" crossorigin="anonymous"> <!-- Bootstrap Icons --> <link rel="stylesheet" href="/static/bootstrap-icons.css"> <style> body { background-color: var(--bs-body-bg); } .main-container { display: flex; flex-direction: column; height: 100vh; padding-top: 1rem; padding-bottom: 1rem; } .settings-panel { height: calc(100vh - 2rem); overflow-y: auto; padding-right: 15px; /* for scrollbar */ } .task-area { height: calc(100vh - 2rem); overflow-y: auto; } .task-card { transition: all 0.3s ease-in-out; } .task-id-placeholder { color: var(--bs-secondary-color); font-style: italic; } .log-area { height: 150px; background-color: var(--bs-tertiary-bg); border: 1px solid var(--bs-border-color); border-radius: .375rem; font-family: monospace; font-size: 0.8rem; padding: 10px; overflow-y: auto; white-space: pre-wrap; word-break: break-all; } .file-drop-area { border: 2px dashed var(--bs-secondary-bg); border-radius: .375rem; padding: 2rem; text-align: center; cursor: pointer; transition: all 0.2s ease-in-out; background-color: var(--bs-body-bg); } .file-drop-area.drag-over { border-color: var(--bs-primary); background-color: var(--bs-secondary-bg); } .file-drop-area.file-selected { border-style: solid; border-color: var(--bs-success); background-color: var(--bs-success-bg-subtle); } .file-drop-area.input-error { border-color: var(--bs-danger); } .file-name-display.input-error-text { color: var(--bs-danger); font-weight: bold; } #printFrame, #translatedPreviewFrame { border: none; width: 100%; } #previewOffcanvas { --bs-offcanvas-width: 95vw; max-width: 1600px; } .preview-split-container { display: flex; flex-direction: row; height: 90%; } .preview-pane-wrapper { display: flex; flex-direction: column; overflow: hidden; /* Important for split.js */ } .preview-pane-wrapper h6 { flex-shrink: 0; padding: 0.25rem; } .preview-pane-wrapper .preview-pane { flex-grow: 1; /* Make the inner pane grow */ border: 1px solid var(--bs-border-color); border-radius: .375rem; overflow: auto; } .gutter { background-color: var(--bs-tertiary-bg); background-repeat: no-repeat; background-position: 50%; } .gutter.gutter-horizontal { cursor: col-resize; border-left: 1px solid var(--bs-border-color); border-right: 1px solid var(--bs-border-color); } .gutter.gutter-vertical { cursor: row-resize; border-top: 1px solid var(--bs-border-color); border-bottom: 1px solid var(--bs-border-color); } .preview-pane iframe, .preview-pane pre { width: 100%; height: 95%; border: none; margin: 0; padding: 0; overflow: auto; background-color: var(--bs-body-bg); } .slider-reset-btn { visibility: hidden; } .bottom-left-controls { position: fixed; bottom: 1rem; left: 1rem; z-index: 1050; display: flex; gap: 0.5rem; } @media (max-width: 991.98px) { .main-container { height: auto; padding-bottom: 6rem; } .settings-panel, .task-area { height: auto; overflow-y: visible; } .settings-panel { padding-right: 0; margin-bottom: 2rem; } } @media (max-width: 767.98px) { .task-card .col-md-7 { margin-top: 1.5rem; } Line truncated
@@ -21,7 +21,7 @@ class AiTranslatorConfig(TranslatorConfig):
chunk_size: int = 3000 chunk_size: int = 3000
concurrent: int = 30 concurrent: int = 30
glossary_dict: dict[str:str] | None = None glossary_dict: dict[str:str] | None = None
glossary_generate_enable: bool = True glossary_generate_enable: bool = False
glossary_agent_config: GlossaryAgentConfig | None = None glossary_agent_config: GlossaryAgentConfig | None = None
@@ -44,7 +44,6 @@ class DocxTranslator(AiTranslator):
baseurl=config.base_url, baseurl=config.base_url,
key=config.api_key, key=config.api_key,
model_id=config.model_id, model_id=config.model_id,
system_prompt=None,
temperature=config.temperature, temperature=config.temperature,
thinking=config.thinking, thinking=config.thinking,
max_concurrent=config.concurrent, max_concurrent=config.concurrent,
@@ -32,7 +32,7 @@ class EpubTranslator(AiTranslator):
agent_config = SegmentsTranslateAgentConfig( agent_config = SegmentsTranslateAgentConfig(
custom_prompt=config.custom_prompt, to_lang=config.to_lang, custom_prompt=config.custom_prompt, to_lang=config.to_lang,
baseurl=config.base_url, key=config.api_key, model_id=config.model_id, baseurl=config.base_url, key=config.api_key, model_id=config.model_id,
system_prompt=None, temperature=config.temperature, thinking=config.thinking, temperature=config.temperature, thinking=config.thinking,
max_concurrent=config.concurrent, timeout=config.timeout, logger=self.logger, max_concurrent=config.concurrent, timeout=config.timeout, logger=self.logger,
glossary_dict=config.glossary_dict glossary_dict=config.glossary_dict
) )
@@ -91,7 +91,6 @@ class HtmlTranslator(AiTranslator):
baseurl=config.base_url, baseurl=config.base_url,
key=config.api_key, key=config.api_key,
model_id=config.model_id, model_id=config.model_id,
system_prompt=None,
temperature=config.temperature, temperature=config.temperature,
thinking=config.thinking, thinking=config.thinking,
max_concurrent=config.concurrent, max_concurrent=config.concurrent,
@@ -23,7 +23,6 @@ class JsonTranslator(AiTranslator):
baseurl=config.base_url, baseurl=config.base_url,
key=config.api_key, key=config.api_key,
model_id=config.model_id, model_id=config.model_id,
system_prompt=None,
temperature=config.temperature, temperature=config.temperature,
thinking=config.thinking, thinking=config.thinking,
max_concurrent=config.concurrent, max_concurrent=config.concurrent,
@@ -24,7 +24,6 @@ class MDTranslator(AiTranslator):
baseurl=config.base_url, baseurl=config.base_url,
key=config.api_key, key=config.api_key,
model_id=config.model_id, model_id=config.model_id,
system_prompt=None,
temperature=config.temperature, temperature=config.temperature,
thinking=config.thinking, thinking=config.thinking,
max_concurrent=config.concurrent, max_concurrent=config.concurrent,
@@ -31,7 +31,6 @@ class SrtTranslator(AiTranslator):
baseurl=config.base_url, baseurl=config.base_url,
key=config.api_key, key=config.api_key,
model_id=config.model_id, model_id=config.model_id,
system_prompt=None,
temperature=config.temperature, temperature=config.temperature,
thinking=config.thinking, thinking=config.thinking,
max_concurrent=config.concurrent, max_concurrent=config.concurrent,
@@ -21,7 +21,6 @@ class TXTTranslator(AiTranslator):
baseurl=config.base_url, baseurl=config.base_url,
key=config.api_key, key=config.api_key,
model_id=config.model_id, model_id=config.model_id,
system_prompt=None,
temperature=config.temperature, temperature=config.temperature,
thinking=config.thinking, thinking=config.thinking,
max_concurrent=config.concurrent, max_concurrent=config.concurrent,
@@ -31,7 +31,6 @@ class XlsxTranslator(AiTranslator):
baseurl=config.base_url, baseurl=config.base_url,
key=config.api_key, key=config.api_key,
model_id=config.model_id, model_id=config.model_id,
system_prompt=None,
temperature=config.temperature, temperature=config.temperature,
thinking=config.thinking, thinking=config.thinking,
max_concurrent=config.concurrent, max_concurrent=config.concurrent,