Skip to content

Commit 85cb3ae

Browse files
committed
sync i18ns
1 parent 7140115 commit 85cb3ae

File tree

2 files changed

+691
-0
lines changed

2 files changed

+691
-0
lines changed

official/docs/prompts.md

Lines changed: 353 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,353 @@
1+
---
2+
sidebar_position: 5
3+
---
4+
# 沉浸式翻译 AI Prompt 配置指南
5+
6+
## 概述
7+
8+
沉浸式翻译支持自定义 AI 翻译的 Prompt 配置,让高级用户可以根据自己的需求调整翻译行为。本文档将详细介绍配置方式、支持的变量以及高级用法。
9+
10+
## 支持的变量
11+
12+
### 基础变量
13+
14+
15+
- `{{text}}` - 需要翻译的文本内容
16+
- `{{from}}` - 源语言
17+
- `{{to}}` - 目标语言
18+
- `{{content_type}}` - 原文本的类型(`html``text`
19+
20+
### 上下文变量
21+
- `{{title_prompt}}` - 网页标题(当可用时)
22+
- `{{summary_prompt}}` - 网页上下文摘要(当可用时)
23+
- `{{terms_prompt}}` - 相关专业术语(当可用时)
24+
25+
26+
## 配置方式
27+
28+
### 1. System Prompt(`systemPrompt`)
29+
以系统身份发送给 AI 的翻译请求。用于设定 AI 的角色和基本规则。
30+
31+
### 2. Prompt(`prompt`)
32+
以用户身份发送给 AI 的对话,包含实际需要翻译的内容。
33+
34+
### 3. System Multiple Prompt(`systemMultiplePrompt`)
35+
当段落数大于 1 时,以系统身份发送给 AI 的翻译请求。用于处理多段落翻译场景。
36+
37+
### 4. Multiple Prompt(`multiplePrompt`)
38+
多段落翻译时,以用户身份发送的请求。支持使用分隔符或 YAML 格式。
39+
40+
### 5. Subtitle Prompt(`subtitlePrompt`)
41+
42+
当需要翻译字幕时,以用户身份发送给 AI 的对话,包含实际需要翻译的内容。
43+
44+
## 默认配置示例
45+
46+
如果只收集到一个段落,那么默认会走单段落的 Prompt, 如果收集到多个段落,那么默认会走多段落的 Prompt,大多数情况会是多段落。多段落的默认分隔符是 `%%`,我们故意使用这个不太常见的分隔符来减少大模型的幻觉。你可以用此 Prompt 为基础去修改为你需要的 Prompt, 以下是默认的 Prompt 配置:
47+
48+
### 单段落翻译
49+
50+
```yaml
51+
systemPrompt: |
52+
You are a professional {{to}} native translator who needs to fluently translate text into {{to}}.
53+
54+
## Translation Rules
55+
1. Output only the translated content, without explanations or additional content (such as "Here's the translation:" or "Translation as follows:")
56+
2. The returned translation must maintain exactly the same number of paragraphs and format as the original text
57+
3. If the text contains HTML tags, consider where the tags should be placed in the translation while maintaining fluency
58+
4. For content that should not be translated (such as proper nouns, code, etc.), keep the original text.
59+
5. Output translation directly (no separators, no extra text){{title_prompt}}{{summary_prompt}}{{terms_prompt}}
60+
prompt: |
61+
Translate to {{to}} (output translation only):
62+
63+
{{text}}
64+
```
65+
66+
### 多段落翻译
67+
68+
```yaml
69+
multipleSystemPrompt: |
70+
You are a professional {{to}} native translator who needs to fluently translate text into {{to}}.
71+
72+
## Translation Rules
73+
1. Output only the translated content, without explanations or additional content (such as "Here's the translation:" or "Translation as follows:")
74+
2. The returned translation must maintain exactly the same number of paragraphs and format as the original text
75+
3. If the text contains HTML tags, consider where the tags should be placed in the translation while maintaining fluency
76+
4. For content that should not be translated (such as proper nouns, code, etc.), keep the original text{{title_prompt}}{{summary_prompt}}{{terms_prompt}}
77+
78+
## Input-Output Format Examples
79+
80+
### Input Example:
81+
Paragraph A
82+
83+
%%
84+
85+
Paragraph B
86+
87+
%%
88+
89+
Paragraph C
90+
91+
%%
92+
93+
Paragraph D
94+
95+
### Output Example:
96+
Translation A
97+
98+
%%
99+
100+
Translation B
101+
102+
%%
103+
104+
Translation C
105+
106+
%%
107+
108+
Translation D
109+
110+
multiplePrompt: |
111+
Translate to {{to}}:
112+
113+
{{text}}
114+
subtitlePrompt: |
115+
Translate to {{to}}:
116+
117+
{{text}}
118+
```
119+
120+
121+
122+
123+
## 高级用法(YAML 格式)
124+
125+
对于需要更精确控制的场景(比如多步骤输出),可以使用 YAML 格式进行配置:
126+
127+
### 高级变量
128+
129+
- `{{yaml}}` - YAML 格式的输入数据
130+
131+
132+
默认的 'yaml' 变量大概长这样;
133+
134+
```
135+
- id: 1
136+
text: Hello world
137+
- id: 2
138+
text: How are you?
139+
```
140+
141+
我们默认期待大模型的输出是这样的:
142+
143+
```
144+
- id: 1
145+
text: 你好世界
146+
- id: 2
147+
text: 你好吗?
148+
```
149+
150+
如果你使用默认的 `{{yaml}}`,那么你需要在 prompt 中把这个期望表达清楚。如果你希望修改默认和响应的 `yaml` 格式,这无法通过沉浸式翻译设置页面中的 UI 来解决,你必须直接编辑沉浸式翻译 JSON 格式的用户配置。
151+
152+
用户配置编辑路径: `设置页`->`开发者设置`->`Edit Full User Config` (编辑前,请备份你的用户配置)
153+
154+
你可以在用户配置的 JSON 中找到翻译服务的配置(如果没有,直接按照这个结构添加即可):
155+
156+
```
157+
{
158+
...
159+
"translationServices": {
160+
"openai": {
161+
...
162+
}
163+
},
164+
...
165+
166+
```
167+
168+
`yaml` 变量由 `env.imt_yaml_item` 组成,所以你可以修改 `imt_yaml_item` 的格式,像下面这样:
169+
170+
```json
171+
"translationServices": {
172+
"openai": {
173+
"env": {
174+
"imt_yaml_item": "- id: {{id}}\n source: {{text}}"
175+
}
176+
}
177+
}
178+
```
179+
180+
另一个特殊变量是 `imt_subtitle_yaml_item`, 和 `imt_yaml_item` 类似,用于翻译字幕的 YAML item.
181+
182+
183+
184+
其他的 `env` 变量,你可以添加任何 `env`变量,直接在 prompt 中按照 `{{变量名}}` 的格式使用,比如如下默认的`env`变量:
185+
186+
- `{{imt_source_field}}` - 原文字段名(默认:text)
187+
- `{{imt_trans_field}}` - 译文字段名(默认:text)
188+
- `{{imt_sub_source_field}}` - 字幕原文字段名
189+
- `{{imt_sub_trans_field}}` - 字幕译文字段名
190+
191+
包括 `title_prompt`,`summary_prompt`,`terms_prompt`背后也是通过 `env`来配置的,默认如下:
192+
193+
194+
```
195+
"title_prompt": "\n\n## Context Awareness\nDocument Metadata:\nTitle: 《{{imt_title}}》",
196+
"summary_prompt": "\n\n## Context Awareness\nDocument Metadata:\nSummary: {{imt_theme}}...",
197+
"terms_prompt": "\n\nRequired Terminology: You MUST use the following terms during translation, If 'source':'target', source == target, keep the source term unchanged.\n\n Terms -> \n\n {{imt_terms}}",
198+
"sub_summary_prompt": "\n\n## Context Awareness\nDocument Metadata:\nType: Subtitle\nSummary: {{imt_theme}}...",
199+
"sub_terms_prompt": "\n\nRequired Terminology: You MUST use the following terms during translation, If 'source':'target', source == target, keep the source term unchanged.\n\n Terms -> \n\n {{imt_terms}}"
200+
201+
```
202+
203+
其中 `imt_title`, `imt_theme`,`imt_terms` 为特殊变量,由系统注入,`imt_title`为标题,`imt_theme`为整个网页的总结,`imt_terms`为模型提取的关键术语。
204+
205+
> 注意: `imt_theme`, `imt_terms` 是专有服务提取的,目前仅为 [Pro 会员](https://immersivetranslate.com/pricing/)提供。
206+
207+
208+
### YAML Prompt 示例
209+
210+
211+
```yaml
212+
systemPrompt: |
213+
You are a professional, authentic machine translation engine.
214+
{{title_prompt}}{{summary_prompt}}{{terms_prompt}}
215+
216+
multiplePrompt: |
217+
You will be given a YAML formatted input containing entries with "id" and "{{imt_source_field}}" fields. Here is the input:
218+
219+
<yaml>
220+
{{yaml}}
221+
</yaml>
222+
223+
For each entry in the YAML, translate the contents of the "{{imt_source_field}}" field into {{to}},{{html_only}} Write the translation back into the "{{imt_source_field}}" field for that entry.
224+
225+
Here is an example of the expected format:
226+
227+
{{normal_result_yaml_example}}
228+
229+
Please return the translated YAML directly without wrapping <yaml> tag or include any additional information.
230+
subtitlePrompt: |
231+
You will be given a YAML formatted subtitles containing entries with "id" and "{{imt_sub_source_field}}" fields. Here is the input:
232+
233+
<yaml>
234+
{{yaml}}
235+
</yaml>
236+
237+
For each entry in the YAML, translate the contents of the "{{imt_sub_source_field}}" field into {{to}},{{html_only}} Write the translation back into the "{{imt_sub_source_field}}" field for that entry.
238+
239+
Here is an example of the expected format:
240+
241+
{{subtitle_result_yaml_example}}
242+
243+
Please return the translated YAML directly without wrapping <yaml> tag or include any additional information.
244+
245+
```
246+
247+
其中 `html_only` 为特殊变量,仅翻译的原文为 HTML 格式时才有,值为: `\n\nPs. if the text contains html tags, please consider after translate, where the tags should be in translated result, meanwhile keep the result fluently.` , 当用户主动在 AI 翻译服务中设置 开启“富文本翻译”时才会有这个变量存在。否则为空。
248+
249+
`normal_result_yaml_example` 在 `env` 中设置,默认为:
250+
251+
```
252+
<example>
253+
Input:
254+
- id: 1
255+
{{imt_source_field}}: Source
256+
Output:
257+
- id: 1
258+
{{imt_trans_field}}: Translation
259+
</example>
260+
```
261+
262+
`subtitle_result_yaml_example` 在 `env` 中设置,默认值为:
263+
264+
```
265+
<example>
266+
Input:
267+
- id: 1
268+
{{imt_sub_source_field}}: ...
269+
- id: 2
270+
{{imt_sub_source_field}}: ...
271+
- id: 3
272+
{{imt_sub_source_field}}: ...
273+
Output:
274+
- id: 1
275+
{{imt_sub_source_field}}: ...
276+
- id: 2
277+
{{imt_sub_source_field}}: ...
278+
- id: 3
279+
{{imt_sub_source_field}}: ...
280+
</example>
281+
282+
```
283+
284+
你可以在 `env` 中覆盖它。
285+
286+
287+
## 高级示例:反思式翻译
288+
289+
这个示例展示了如何使用 YAML 格式实现更复杂的翻译流程,包含初步翻译和优化翻译两个步骤:
290+
291+
```yaml
292+
env:
293+
imt_source_field: source
294+
imt_trans_field: step2 # 最终译文使用 step2 字段
295+
imt_sub_source_field: source
296+
imt_sub_trans_field: step2
297+
imt_yaml_item: |-
298+
- id: {{id}}
299+
{{imt_source_field}}: {{text}}
300+
imt_subtitle_yaml_item: |-
301+
- id: {{id}}
302+
{{imt_sub_source_field}}: {{text}}
303+
304+
systemPrompt: |
305+
You are a professional, authentic machine translation engine.
306+
{{title_prompt}}{{summary_prompt}}{{terms_prompt}}
307+
308+
multiplePrompt: |
309+
Here is the YAML input:
310+
<yaml>
311+
{{yaml}}
312+
</yaml>
313+
314+
Please follow these steps:
315+
1. Extract the content from the "source" field in the provided YAML object.
316+
2. Translate the extracted content into {{to}}. Place this initial translation into the step1 field.
317+
3. Refine the initial translation from step1 to make it more natural and understandable in {{to}}.
318+
Place this refined translation into the step2 field.
319+
4. Format the result as a YAML array with id, step1, and step2 fields as shown in this example:
320+
321+
- id: 1
322+
step1: Initial translation
323+
step2: Refined translation
324+
325+
Return the translated YAML directly without any <example_output> tags or additional information.
326+
```
327+
328+
### 工作流程说明
329+
330+
1. **输入格式**
331+
```yaml
332+
- id: 1
333+
source: "Hello world"
334+
- id: 2
335+
source: "How are you?"
336+
```
337+
338+
2. **AI 处理步骤**:
339+
- Step 1: 进行初步翻译
340+
- Step 2: 优化翻译,使其更自然流畅
341+
342+
3. **输出格式**:
343+
```yaml
344+
- id: 1
345+
step1: "你好世界"
346+
step2: "你好,世界"
347+
- id: 2
348+
step1: "你怎么样?"
349+
step2: "你好吗?"
350+
```
351+
352+
353+

0 commit comments

Comments
 (0)