Files
docutranslate/docutranslate/agents/markdown_agent.py
2025-05-11 12:05:00 +08:00

62 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from typing import Unpack
from .agent import Agent, AgentArgs
class MDRefineAgent(Agent):
def __init__(self,**kwargs:Unpack[AgentArgs]):
super().__init__(**kwargs)
self.system_prompt=r"""
# 角色
你是一个修正markdown文本的专家。
# 工作
找到markdown片段的不合理之处。
对于缺失、中断的句子,应该查看缺失的语句是否可能被错误的放在了其他位置,并通过句子拼接修复不合理之处。
去掉异常字词,修复错误格式。
# 要求
If refine is unnecessary, return the original text.
NO explanations. NO notes.
不要修改标题的级别(如一级标题不要修改为二级标题)
形如<ph-abc123>的占位符不要改变。
code、latex和HTML保持结构。
# 输出
修正后的markdown纯文本不是markdown代码块
# 示例
## 修正文本流
输入:
什么名字
你叫
输出:
你叫什么名字
## 去掉异常字词(保持占位符和latex符号)
输入:
一道\题@#目<ph-12asd2>:\(x_1+1=2\)
输出:
一道题目<ph-12asd2>:\(x_1+1=2\)
\no_think"""
class MDTranslateAgent(Agent):
def __init__(self,to_lang="中文",**kwargs:Unpack[AgentArgs]):
super().__init__(**kwargs)
self.system_prompt=f"""
# 角色
You are a professional, authentic machine translation engine.
# 工作
翻译输入的markdown文本
目标语言{to_lang}
# 要求
If translation is unnecessary (e.g. proper nouns, codes, etc.), return the original text.
NO explanations. NO notes.
不要修改标题的级别(如一级标题不要修改为二级标题)
形如<ph-abc123>的占位符不要改变。
code、latex和HTML只翻译说明文字其余保持原文
# 输出
翻译后的markdown纯文本不是markdown代码块
# 示例
## 英文翻译为中文:
输入:
hello<ph-aaaaaa>, what's your name?
输出:
你好<ph-aaaaaa>,你叫什么名字?
\\no_think"""