Skip to content

Commit 820f40e

Browse files
committed
sync i18ns
1 parent 86b47a6 commit 820f40e

File tree

1 file changed

+338
-0
lines changed
  • official/i18n/zh-TW/docusaurus-plugin-content-docs/current

1 file changed

+338
-0
lines changed
Lines changed: 338 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,338 @@
1+
---
2+
sidebar_position: 5
3+
---
4+
# AI Prompt 配置指南
5+
6+
## 概述
7+
8+
沉浸式翻譯支援自定義 AI 翻譯的 Prompt 配置,讓進階使用者可以根據自己的需求調整翻譯行為。本文件將詳細介紹配置方式、支援的變數以及進階用法。
9+
10+
## 支援的變數
11+
12+
### 基礎變數
13+
14+
- `{{text}}` - 需要翻譯的文字內容
15+
- `{{from}}` - 來源語言
16+
- `{{to}}` - 目標語言
17+
- `{{content_type}}` - 原文字的類型(`html``text`
18+
19+
### 上下文變數
20+
- `{{title_prompt}}` - 網頁標題(當可用時)
21+
- `{{summary_prompt}}` - 網頁上下文摘要(當可用時)
22+
- `{{terms_prompt}}` - 相關專業術語(當可用時)
23+
24+
## 配置方式
25+
26+
### 1. System Prompt(`systemPrompt`)
27+
以系統身份發送給 AI 的翻譯請求。用於設定 AI 的角色和基本規則。
28+
29+
### 2. Prompt(`prompt`)
30+
以使用者身份發送給 AI 的對話,包含實際需要翻譯的內容。
31+
32+
### 3. System Multiple Prompt(`systemMultiplePrompt`)
33+
當段落數大於 1 時,以系統身份發送給 AI 的翻譯請求。用於處理多段落翻譯場景。
34+
35+
### 4. Multiple Prompt(`multiplePrompt`)
36+
多段落翻譯時,以使用者身份發送的請求。支援使用分隔符或 YAML 格式。
37+
38+
### 5. Subtitle Prompt(`subtitlePrompt`)
39+
40+
當需要翻譯字幕時,以使用者身份發送給 AI 的對話,包含實際需要翻譯的內容。
41+
42+
## 預設配置範例
43+
44+
如果只收集到一個段落,那麼預設會走單段落的 Prompt,如果收集到多個段落,那麼預設會走多段落的 Prompt,大多數情況會是多段落。多段落的預設分隔符是 `%%`,我們故意使用這個不太常見的分隔符來減少大模型的幻覺。你可以用此 Prompt 為基礎去修改為你需要的 Prompt,以下是預設的 Prompt 配置:
45+
46+
### 單段落翻譯
47+
48+
```yaml
49+
systemPrompt: |
50+
You are a professional {{to}} native translator who needs to fluently translate text into {{to}}.
51+
52+
## Translation Rules
53+
1. Output only the translated content, without explanations or additional content (such as "Here's the translation:" or "Translation as follows:")
54+
2. The returned translation must maintain exactly the same number of paragraphs and format as the original text
55+
3. If the text contains HTML tags, consider where the tags should be placed in the translation while maintaining fluency
56+
4. For content that should not be translated (such as proper nouns, code, etc.), keep the original text.
57+
5. Output translation directly (no separators, no extra text){{title_prompt}}{{summary_prompt}}{{terms_prompt}}
58+
prompt: |
59+
Translate to {{to}} (output translation only):
60+
61+
{{text}}
62+
```
63+
64+
### 多段落翻譯
65+
66+
```yaml
67+
multipleSystemPrompt: |
68+
You are a professional {{to}} native translator who needs to fluently translate text into {{to}}.
69+
70+
## Translation Rules
71+
1. Output only the translated content, without explanations or additional content (such as "Here's the translation:" or "Translation as follows:")
72+
2. The returned translation must maintain exactly the same number of paragraphs and format as the original text
73+
3. If the text contains HTML tags, consider where the tags should be placed in the translation while maintaining fluency
74+
4. For content that should not be translated (such as proper nouns, code, etc.), keep the original text{{title_prompt}}{{summary_prompt}}{{terms_prompt}}
75+
76+
## Input-Output Format Examples
77+
78+
### Input Example:
79+
Paragraph A
80+
81+
%%
82+
83+
Paragraph B
84+
85+
%%
86+
87+
Paragraph C
88+
89+
%%
90+
91+
Paragraph D
92+
93+
### Output Example:
94+
Translation A
95+
96+
%%
97+
98+
Translation B
99+
100+
%%
101+
102+
Translation C
103+
104+
%%
105+
106+
Translation D
107+
108+
multiplePrompt: |
109+
Translate to {{to}}:
110+
111+
{{text}}
112+
subtitlePrompt: |
113+
Translate to {{to}}:
114+
115+
{{text}}
116+
```
117+
118+
## 進階用法(YAML 格式)
119+
120+
對於需要更精確控制的場景(比如多步驟輸出),可以使用 YAML 格式進行配置:
121+
122+
### 進階變數
123+
124+
- `{{yaml}}` - YAML 格式的輸入資料
125+
126+
預設的 'yaml' 變數大概長這樣:
127+
128+
```
129+
- id: 1
130+
text: Hello world
131+
- id: 2
132+
text: How are you?
133+
```
134+
135+
我們預設期待大模型的輸出是這樣的:
136+
137+
```
138+
- id: 1
139+
text: 你好世界
140+
- id: 2
141+
text: 你好嗎?
142+
```
143+
144+
如果你使用預設的 `{{yaml}}`,那麼你需要在 prompt 中把這個期望表達清楚。如果你希望修改預設和響應的 `yaml` 格式,這無法透過沉浸式翻譯設定頁面中的 UI 來解決,你必須直接編輯沉浸式翻譯 JSON 格式的使用者配置。
145+
146+
使用者配置編輯路徑:`設定頁`->`開發者設定`->`Edit Full User Config`(編輯前,請備份你的使用者配置)
147+
148+
你可以在使用者配置的 JSON 中找到翻譯服務的配置(如果沒有,直接按照這個結構新增即可):
149+
150+
```
151+
{
152+
...
153+
"translationServices": {
154+
"openai": {
155+
...
156+
}
157+
},
158+
...
159+
160+
```
161+
162+
`yaml` 變數由 `env.imt_yaml_item` 組成,所以你可以修改 `imt_yaml_item` 的格式,像下面這樣:
163+
164+
```json
165+
"translationServices": {
166+
"openai": {
167+
"env": {
168+
"imt_yaml_item": "- id: {{id}}\n source: {{text}}"
169+
}
170+
}
171+
}
172+
```
173+
174+
另一個特殊變數是 `imt_subtitle_yaml_item`,和 `imt_yaml_item` 類似,用於翻譯字幕的 YAML item。
175+
176+
其他的 `env` 變數,你可以新增任何 `env` 變數,直接在 prompt 中按照 `{{變數名}}` 的格式使用,比如如下預設的 `env` 變數:
177+
178+
- `{{imt_source_field}}` - 原文欄位名(預設:text)
179+
- `{{imt_trans_field}}` - 譯文欄位名(預設:text)
180+
- `{{imt_sub_source_field}}` - 字幕原文欄位名
181+
- `{{imt_sub_trans_field}}` - 字幕譯文欄位名
182+
183+
包括 `title_prompt``summary_prompt``terms_prompt` 背後也是透過 `env` 來配置的,預設如下:
184+
185+
```
186+
"title_prompt": "\n\n## Context Awareness\nDocument Metadata:\nTitle: 《{{imt_title}}》",
187+
"summary_prompt": "\n\n## Context Awareness\nDocument Metadata:\nSummary: {{imt_theme}}...",
188+
"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}}",
189+
"sub_summary_prompt": "\n\n## Context Awareness\nDocument Metadata:\nType: Subtitle\nSummary: {{imt_theme}}...",
190+
"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}}"
191+
192+
```
193+
194+
其中 `imt_title``imt_theme``imt_terms` 為特殊變數,由系統注入,`imt_title` 為標題,`imt_theme` 為整個網頁的總結,`imt_terms` 為模型提取的關鍵術語。
195+
196+
> 注意:`imt_theme``imt_terms` 是專有服務提取的,目前僅為 [Pro 會員](https://immersivetranslate.com/pricing/) 提供。
197+
198+
### YAML Prompt 範例
199+
200+
```yaml
201+
systemPrompt: |
202+
You are a professional, authentic machine translation engine.
203+
{{title_prompt}}{{summary_prompt}}{{terms_prompt}}
204+
205+
multiplePrompt: |
206+
You will be given a YAML formatted input containing entries with "id" and "{{imt_source_field}}" fields. Here is the input:
207+
208+
<yaml>
209+
{{yaml}}
210+
</yaml>
211+
212+
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.
213+
214+
Here is an example of the expected format:
215+
216+
{{normal_result_yaml_example}}
217+
218+
Please return the translated YAML directly without wrapping <yaml> tag or include any additional information.
219+
subtitlePrompt: |
220+
You will be given a YAML formatted subtitles containing entries with "id" and "{{imt_sub_source_field}}" fields. Here is the input:
221+
222+
<yaml>
223+
{{yaml}}
224+
</yaml>
225+
226+
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.
227+
228+
Here is an example of the expected format:
229+
230+
{{subtitle_result_yaml_example}}
231+
232+
Please return the translated YAML directly without wrapping <yaml> tag or include any additional information.
233+
234+
```
235+
236+
其中 `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 翻譯服務中設定開啟「富文字翻譯」時才會有這個變數存在。否則為空。
237+
238+
`normal_result_yaml_example` 在 `env` 中設定,預設為:
239+
240+
```
241+
<example>
242+
Input:
243+
- id: 1
244+
{{imt_source_field}}: Source
245+
Output:
246+
- id: 1
247+
{{imt_trans_field}}: Translation
248+
</example>
249+
```
250+
251+
`subtitle_result_yaml_example` 在 `env` 中設定,預設值為:
252+
253+
```
254+
<example>
255+
Input:
256+
- id: 1
257+
{{imt_sub_source_field}}: ...
258+
- id: 2
259+
{{imt_sub_source_field}}: ...
260+
- id: 3
261+
{{imt_sub_source_field}}: ...
262+
Output:
263+
- id: 1
264+
{{imt_sub_source_field}}: ...
265+
- id: 2
266+
{{imt_sub_source_field}}: ...
267+
- id: 3
268+
{{imt_sub_source_field}}: ...
269+
</example>
270+
271+
```
272+
273+
你可以在 `env` 中覆蓋它。
274+
275+
## 進階範例:反思式翻譯
276+
277+
這個範例展示了如何使用 YAML 格式實現更複雜的翻譯流程,包含初步翻譯和最佳化翻譯兩個步驟:
278+
279+
```yaml
280+
env:
281+
imt_source_field: source
282+
imt_trans_field: step2 # 最終譯文使用 step2 欄位
283+
imt_sub_source_field: source
284+
imt_sub_trans_field: step2
285+
imt_yaml_item: |-
286+
- id: {{id}}
287+
{{imt_source_field}}: {{text}}
288+
imt_subtitle_yaml_item: |-
289+
- id: {{id}}
290+
{{imt_sub_source_field}}: {{text}}
291+
292+
systemPrompt: |
293+
You are a professional, authentic machine translation engine.
294+
{{title_prompt}}{{summary_prompt}}{{terms_prompt}}
295+
296+
multiplePrompt: |
297+
Here is the YAML input:
298+
<yaml>
299+
{{yaml}}
300+
</yaml>
301+
302+
Please follow these steps:
303+
1. Extract the content from the "source" field in the provided YAML object.
304+
2. Translate the extracted content into {{to}}. Place this initial translation into the step1 field.
305+
3. Refine the initial translation from step1 to make it more natural and understandable in {{to}}.
306+
Place this refined translation into the step2 field.
307+
4. Format the result as a YAML array with id, step1, and step2 fields as shown in this example:
308+
309+
- id: 1
310+
step1: Initial translation
311+
step2: Refined translation
312+
313+
Return the translated YAML directly without any <example_output> tags or additional information.
314+
```
315+
316+
### 工作流程說明
317+
318+
1. **輸入格式**
319+
```yaml
320+
- id: 1
321+
source: "Hello world"
322+
- id: 2
323+
source: "How are you?"
324+
```
325+
326+
2. **AI 處理步驟**:
327+
- Step 1: 進行初步翻譯
328+
- Step 2: 最佳化翻譯,使其更自然流暢
329+
330+
3. **輸出格式**:
331+
```yaml
332+
- id: 1
333+
step1: "你好世界"
334+
step2: "你好,世界"
335+
- id: 2
336+
step1: "你怎麼樣?"
337+
step2: "你好嗎?"
338+
```

0 commit comments

Comments
 (0)