优化提示词
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from json import JSONDecodeError
|
||||||
|
|
||||||
from docutranslate.agents import AgentConfig, Agent
|
from docutranslate.agents import AgentConfig, Agent
|
||||||
from docutranslate.utils.json_utils import flat_json_split
|
from docutranslate.utils.json_utils import flat_json_split
|
||||||
@@ -27,7 +28,7 @@ class SegmentsTranslateAgent(Agent):
|
|||||||
翻译后的片段应该与源格式尽量相同
|
翻译后的片段应该与源格式尽量相同
|
||||||
如果待翻译片段已经是目标语言,则保持原样
|
如果待翻译片段已经是目标语言,则保持原样
|
||||||
# 输出
|
# 输出
|
||||||
翻译后的片段序列,以json格式表示。其中键是片段编号,值是翻译后的片段
|
翻译后的片段序列,以json文本表示(文本而非代码块)。其中键是片段编号,值是翻译后的片段
|
||||||
# 示例
|
# 示例
|
||||||
## 输入
|
## 输入
|
||||||
{r'{"0":"hello","1":"apple","2":true,"3":"false"}'}
|
{r'{"0":"hello","1":"apple","2":true,"3":"false"}'}
|
||||||
@@ -56,6 +57,10 @@ class SegmentsTranslateAgent(Agent):
|
|||||||
translated_chunks = await super().send_prompts_async(prompts=prompts)
|
translated_chunks = await super().send_prompts_async(prompts=prompts)
|
||||||
indexed_translated = indexed_originals.copy()
|
indexed_translated = indexed_originals.copy()
|
||||||
for chunk_str in translated_chunks:
|
for chunk_str in translated_chunks:
|
||||||
|
try:
|
||||||
translated_part = json.loads(chunk_str)
|
translated_part = json.loads(chunk_str)
|
||||||
indexed_translated.update(translated_part)
|
indexed_translated.update(translated_part)
|
||||||
|
except JSONDecodeError as e:
|
||||||
|
self.logger.info(f"json解析错误,解析文本:{chunk_str},错误:{e.__repr__()}")
|
||||||
|
|
||||||
return list(indexed_translated.values())
|
return list(indexed_translated.values())
|
||||||
|
|||||||
@@ -52,11 +52,10 @@ class Xlsx2HTMLExporter(XlsxExporter):
|
|||||||
|
|
||||||
html_template = resource_path("template/xlsx.html").read_text(encoding="utf-8")
|
html_template = resource_path("template/xlsx.html").read_text(encoding="utf-8")
|
||||||
|
|
||||||
pico = f'<style>{resource_path("static/pico.css").read_text(encoding="utf-8")}</style>' if not cdn else r'<link rel="stylesheet" href="https://s4.zstatic.net/ajax/libs/picocss/2.1.1/pico.min.css" integrity="sha512-+4kjFgVD0n6H3xt19Ox84B56MoS7srFn60tgdWFuO4hemtjhySKyW4LnftYZn46k3THUEiTTsbVjrHai+0MOFw==" crossorigin="anonymous" referrerpolicy="no-referrer" />'
|
pico = f'<style>{resource_path("static/pico.css").read_text(encoding="utf-8")}</style>' if not self.cdn else r'<link rel="stylesheet" href="https://s4.zstatic.net/ajax/libs/picocss/2.1.1/pico.min.css" integrity="sha512-+4kjFgVD0n6H3xt19Ox84B56MoS7srFn60tgdWFuO4hemtjhySKyW4LnftYZn46k3THUEiTTsbVjrHai+0MOFw==" crossorigin="anonymous" referrerpolicy="no-referrer" />'
|
||||||
render = jinja2.Template(html_template).render(
|
render = jinja2.Template(html_template).render(
|
||||||
title=document.stem,
|
title=document.stem,
|
||||||
pico=pico,
|
pico=pico,
|
||||||
body=table,
|
body=table,
|
||||||
)
|
)
|
||||||
print("\n通过openpyxl手动生成了 output_manual.html 文件!")
|
|
||||||
return Document.from_bytes(content=render.encode("utf-8"), suffix=".html", stem=document.stem)
|
return Document.from_bytes(content=render.encode("utf-8"), suffix=".html", stem=document.stem)
|
||||||
|
|||||||
Reference in New Issue
Block a user