diff --git a/book_maker/cli.py b/book_maker/cli.py
index c5b823d..5c71492 100644
--- a/book_maker/cli.py
+++ b/book_maker/cli.py
@@ -35,8 +35,9 @@ def parse_prompt_arg(prompt_arg):
else:
raise FileNotFoundError(f"{prompt_arg} not found")
- if prompt is None or any(c not in prompt["user"] for c in ["{text}", "{language}"]):
- raise ValueError("prompt must contain `{text}` and `{language}`")
+ #if prompt is None or any(c not in prompt["user"] for c in ["{text}", "{language}"]):
+ if prompt is None or any(c not in prompt["user"] for c in ["{text}"]):
+ raise ValueError("prompt must contain `{text}`")
if "user" not in prompt:
raise ValueError("prompt must contain the key of `user`")
diff --git a/book_maker/translator/gemini_translator.py b/book_maker/translator/gemini_translator.py
index 9a79836..99cbc9e 100644
--- a/book_maker/translator/gemini_translator.py
+++ b/book_maker/translator/gemini_translator.py
@@ -43,6 +43,7 @@ GEMINIFLASH_MODEL_LIST = [
"gemini-1.5-flash-latest",
"gemini-1.5-flash-001",
"gemini-1.5-flash-002",
+ "gemini-2.0-flash-exp",
]
@@ -119,6 +120,13 @@ class Gemini(Base):
self.prompt.format(text=text, language=self.language)
)
t_text = self.convo.last.text.strip()
+ # 检查是否包含特定标签,如果有则只返回标签内的内容
+ tag_pattern = r'(.*?)'
+ tag_match = re.search(tag_pattern, t_text, re.DOTALL)
+ if tag_match:
+ print("[bold green]" + re.sub("\n{3,}", "\n\n", t_text) + "[/bold green]")
+ t_text = tag_match.group(1).strip()
+ #print("[bold green]" + re.sub("\n{3,}", "\n\n", t_text) + "[/bold green]")
break
except StopCandidateException as e:
print(
diff --git a/prompt_template_sample.json b/prompt_template_sample.json
index 02b8aea..54bd372 100644
--- a/prompt_template_sample.json
+++ b/prompt_template_sample.json
@@ -1,4 +1,4 @@
{
- "system": "You are a professional translator.",
- "user": "Translate the given text to {language}. Be faithful or accurate in translation. Make the translation readable or intelligible. Be elegant or natural in translation. If the text cannot be translated, return the original text as is. Do not translate person's name. Do not add any additional text in the translation. The text to be translated is:\n{text}"
-}
+ "system": "您是一位技术精湛的翻译人员,负责将书籍的内容从其他语言翻译成中文。",
+ "user": "## 策略\n您将遵循三步翻译流程:\n1. 将输入的内容翻译成中文,尊重原文意图,保持原始SRT格式不变,不删除或省略任何内容,也不添加额外的解释或说明。\n2. 仔细阅读原文和译文,然后提出建设性的批评和有益的建议以改进翻译。翻译的最终风格和语气应符合中文语言风格。写建议时,注意是否有办法改进翻译的\n- 准确性 (通过纠正添加、误译、遗漏或未翻译文本的错误)\n- 流畅性 (通过应用中文语法、拼写和标点符号规则,并确保没有不必要的重复)\n- 精简缩写 (请在保持原意不变的情况下尽量精简缩写翻译结果,避免翻译结果冗长)\n3. 根据步骤1和2的结果,完善和润色翻译,不要添加额外的解释、说明。\n\n## 输出\n\n对于翻译过程的每个步骤,在适当的 XML 标签中输出结果:\n\n\n[在此插入您的初始翻译]\n\n\n\n[插入您对翻译的反思,提出具体、有用且建设性的建议,以改进翻译。每个建议都应针对翻译的一个特定部分。]\n\n\n\n[在此处插入您精炼和润色后的翻译]\n\n\n以下标签内是需要翻译的书籍内容:\n{text}"
+}
\ No newline at end of file