Skip to content

Commit 3784875

Browse files
committed
Make prompty more DRY
1 parent 70be96e commit 3784875

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

pontoon/machinery/openai_service.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ def get_translation(
2222
f"The target language '{target_language_name}' is not supported."
2323
)
2424

25+
intro_text = f"Refine the {target_language_name} machine translation to make it {characteristic}."
26+
2527
common_rules = textwrap.dedent(
26-
"""1) ENDING PUNCTUATION — SEMANTICS, NOT LITERAL CHAR:
28+
"""Follow these rules IN ORDER OF PRIORITY:
29+
1) ENDING PUNCTUATION — SEMANTICS, NOT LITERAL CHAR:
2730
- Detect the English ending: none, ".", "?", "!", "…".
2831
- The translation MUST express the same ending SEMANTIC:
2932
• if English ends with "?" → translation ends with a question.
@@ -36,18 +39,16 @@ def get_translation(
3639
)
3740

3841
informal = textwrap.dedent(
39-
f"""You will be provided with text in English, along with its machine-generated translation in {target_language}.
42+
f"""{intro_text}
4043
Revise the {target_language} translation to use simpler language,
41-
Follow these rules IN ORDER OF PRIORITY:
4244
{common_rules}
4345
3) Clarity and Simplicity: keep wording straightforward and consistent.
4446
Output only the revised translation."""
4547
)
4648

4749
formal = textwrap.dedent(
48-
f"""You will be provided with text in English, along with its machine-generated translation in {target_language}.
50+
f"""{intro_text}
4951
Revise the {target_language} translation to use a higher level of formality.
50-
Follow these rules IN ORDER OF PRIORITY:
5152
{common_rules}
5253
3) Consistency: maintain a consistent level of formality throughout; do not mix formal and informal modes.
5354
4) Preserve all HTML tags and their order. Do not add, remove, or reorder tags.
@@ -56,9 +57,8 @@ def get_translation(
5657
)
5758

5859
rephrased = textwrap.dedent(
59-
f"""You will be provided with text in English, along with its machine-generated translation in {target_language}.
60+
f"""{intro_text}
6061
Provide an alternative translation that preserves the original meaning while varying the wording.
61-
Follow these rules IN ORDER OF PRIORITY:
6262
{common_rules}
6363
3) Cultural and Idiomatic Fit: adapt idioms and culturally marked expressions appropriately for {target_language}; you may restructure sentences but must not introduce new information or omit essential meaning.
6464
4) Clarity and Naturalness: ensure the result reads naturally and is easy to understand.

0 commit comments

Comments
 (0)