改进提示词

This commit is contained in:
xunbu
2025-05-29 20:13:58 +08:00
parent f6766a8799
commit 097efa6cb5
5 changed files with 23 additions and 21 deletions

View File

@@ -1,4 +1,4 @@
__version__="0.2.31" __version__="0.2.32"

View File

@@ -51,33 +51,33 @@ class MDTranslateAgent(Agent):
# 工作 # 工作
翻译输入的markdown文本 翻译输入的markdown文本
目标语言{to_lang} 目标语言{to_lang}
# 要求【必须严格遵守】 # 要求
翻译要求专业准确 翻译要求专业准确
不输出任何解释和注释 不输出任何解释和注释
引用的参考文献名及其作者名不翻译 不能改变形如<ph-xxxxxx>的占位符
不要改变形如<ph-xxxxxx>的占位符【重要】
code、latex和HTML只翻译说明文字其余保持原文 code、latex和HTML只翻译说明文字其余保持原文
公式必须表示为合法latex公式,行内公式需被$或\\(\\)正确包裹 公式无论长短必须表示为能被解析的合法latex公式,公式需被$或\\(\\)或$$正确包裹
去除、修正明显异常的字符、但不能改变原意
参考文献的引用及其作者名保持源语言不要翻译。引用的参考文献示例如下:
> [1] Nofer M, Gomber P, Hinz O, et al. Blockchain[J]. systems engineering, 2017, 59: 183-187.
# 输出 # 输出
翻译后的markdown译文纯文本不是markdown代码块无任何多余文字 翻译后的markdown译文纯文本不是markdown代码块无任何多余文字
# 示例 # 示例
## 英文翻译为中文 ## 目标语言为中文
输入: 输入:
hello<ph-12asd2>, what's your nam*@e? hello, what's your nam*@e?
![photo title](<ph-abcdde>) ![photo title](<ph-abcdde>)
输出:
你好<ph-12asd2>,你叫什么名字?
![图像标题](<ph-abcdde>)
## 公式要为合法latex行内公式应正确包裹
输入:
The equation is E=mc 2. This is famous. The equation is E=mc 2. This is famous.
(c_0,c_1,c_2^2)is a coordinate. (c_0,c_1_1,c_2^2)is a coordinate.
1+1=2$$
[2]Lasi H, Fettke P, Kemper H G, et al. Industry 4.0[J]. Information systems engineering, 2014, 6: 239-242.
输出: 输出:
你好,你叫什么名字?
![图像标题](<ph-abcdde>)
这个方程是 $E=mc^2$。这很有名。 这个方程是 $E=mc^2$。这很有名。
$$1+1=2$$
\\((c_0,c_1,c_2^2)\\)是一个坐标。 \\((c_0,c_1,c_2^2)\\)是一个坐标。
## 引用参考文献时请严格保持原文(包括语言),不要翻译。参考文献格式示例: [2]Lasi H, Fettke P, Kemper H G, et al. Industry 4.0[J]. Information systems engineering, 2014, 6: 239-242."""
> [1] Author A, Author B. "Original Title". Journal, 2023.
> [2] 作者C. 《中文标题》. 期刊, 2022."""
if custom_prompt: if custom_prompt:
self.system_prompt += "\n# 重要规则或背景【非常重要】\n" + custom_prompt + '\n' self.system_prompt += "\n# 重要规则或背景【非常重要】\n" + custom_prompt + '\n'
self.system_prompt += r'\no_think' self.system_prompt += r'\no_think'

View File

@@ -443,7 +443,7 @@ def run_app():
if port != initial_port: if port != initial_port:
print(f"端口 {initial_port} 被占用,将使用端口 {port} 代替") print(f"端口 {initial_port} 被占用,将使用端口 {port} 代替")
print("正在启动 DocuTranslate WebUI") print("正在启动 DocuTranslate WebUI")
print(f"请用浏览器访问 http://127.0.0.1:{port}") print(f"请用浏览器访问 http://127.0.0.1:{port} (部分终端可以使用ctrl+左键点击网址打开)")
uvicorn.run(app, host="127.0.0.1", port=port, workers=1) uvicorn.run(app, host="127.0.0.1", port=port, workers=1)
except Exception as e: except Exception as e:
print(f"启动失败: {e}") print(f"启动失败: {e}")

View File

@@ -360,7 +360,7 @@
<div class="form-group"> <div class="form-group">
<label for="convert_engin">解析引擎</label> <label for="convert_engin">解析引擎</label>
<select id="convert_engin" name="convert_engin"> <select id="convert_engin" name="convert_engin">
<option value="mineru" selected>minerU</option> <option value="mineru" selected>minerU(推荐)</option>
<option value="docling" id="docling">Docling</option> <option value="docling" id="docling">Docling</option>
</select> </select>
</div> </div>

View File

@@ -52,6 +52,8 @@ class FileTranslater:
def _markdown_format(self): def _markdown_format(self):
# 该方法还需要改进 # 该方法还需要改进
# self.markdown=mdformat.text(self.markdown) # self.markdown=mdformat.text(self.markdown)
self.markdown=self.markdown.replace(r'\',r'\(')
self.markdown = self.markdown.replace(r'\', r'\)')
pass pass
def _mask_uris_in_markdown(self): def _mask_uris_in_markdown(self):
@@ -310,9 +312,9 @@ class FileTranslater:
auto_render = f'<script>{resource_path("static/autoRender.js").read_text(encoding='utf-8')}</script>' if not cdn else r"""<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/contrib/auto-render.min.js" integrity="sha384-hCXGrW6PitJEwbkoStFjeJxv+fSOOQKOPbJxSfM6G5sWZjAyWhXiTIIAmQqnlLlh" crossorigin="anonymous"></script>""" auto_render = f'<script>{resource_path("static/autoRender.js").read_text(encoding='utf-8')}</script>' if not cdn else r"""<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.22/dist/contrib/auto-render.min.js" integrity="sha384-hCXGrW6PitJEwbkoStFjeJxv+fSOOQKOPbJxSfM6G5sWZjAyWhXiTIIAmQqnlLlh" crossorigin="anonymous"></script>"""
mermaid = f'<script>{resource_path("static/mermaid.js").read_text(encoding='utf-8')}</script>' mermaid = f'<script>{resource_path("static/mermaid.js").read_text(encoding='utf-8')}</script>'
if self.file_suffix == ".txt": if self.file_suffix == ".txt":
content = html.escape(self.markdown).replace("\n", "<br>") content = html.escape(self.export_to_markdown()).replace("\n", "<br>")
else: else:
content = markdowner.convert(self.markdown.replace("\\", "\\\\")) content = markdowner.convert(self.export_to_markdown().replace("\\", "\\\\"))
# TODO:实现MathJax本地化 # TODO:实现MathJax本地化
render = jinja2.Template(html_template).render( render = jinja2.Template(html_template).render(
title=title, title=title,