You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
DEV: Switch translations out of structured output as it returns only a single value (#1503)
Since translations only require a single key back, there is little point in using structured output. This PR also includes some prompt updates dealing with quotes, details, and code.
Related: #1502
This does mean reverting discourse/discourse-translator#257, but we can see how it goes.
Copy file name to clipboardExpand all lines: lib/personas/locale_detector.rb
+7-28Lines changed: 7 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -34,43 +34,22 @@ def system_prompt
34
34
35
35
5. Avoid using `und` and prefer `en` over `en-US` or `en-GB` unless the text specifically indicates a regional variant.
36
36
37
-
6. Format your response as a JSON object with a single key "locale" and the value as the language code.
37
+
Two example scenarios:
38
+
Input: "Can you tell me what '私の世界で一番好きな食べ物はちらし丼です' means?"
39
+
Output: "en"
38
40
39
-
Your output should be in the following format:
40
-
<output>
41
-
{"locale": "xx"}
42
-
</output>
43
-
44
-
Where "xx" is replaced by the appropriate language code.
41
+
Input: [quote]\nNon smettere mai di credere nella bellezza dei tuoi sogni. Anche quando tutto sembra perduto, c'è sempre una luce che aspetta di essere trovata.\nOgni passo, anche il più piccolo, ti avvicina a ciò che desideri. La forza che cerchi è già dentro di te.\n[/quote]\n¿Cuál es el mensaje principal de esta cita?
42
+
Output: "es"
45
43
46
44
Important: Base your analysis solely on the provided text. Do not use any external information or make assumptions about the text's origin or context beyond what is explicitly provided.
47
-
PROMPT
48
-
end
49
45
50
-
defresponse_format
51
-
[{"key"=>"locale","type"=>"string"}]
46
+
Your response must be a language code, and nothing else.
47
+
PROMPT
52
48
end
53
49
54
50
deftemperature
55
51
0
56
52
end
57
-
58
-
defexamples
59
-
spanish=<<~MARKDOWN
60
-
[quote]
61
-
Non smettere mai di credere nella bellezza dei tuoi sogni. Anche quando tutto sembra perduto, c'è sempre una luce che aspetta di essere trovata.
62
-
63
-
Ogni passo, anche il più piccolo, ti avvicina a ciò che desideri. La forza che cerchi è già dentro di te.
64
-
[/quote]
65
-
66
-
¿Cuál es el mensaje principal de esta cita?
67
-
MARKDOWN
68
-
69
-
[
70
-
["Can you tell me what '私の世界で一番好きな食べ物はちらし丼です' means?",{locale: "en"}.to_json],
Copy file name to clipboardExpand all lines: lib/personas/post_raw_translator.rb
+45-33Lines changed: 45 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -8,62 +8,74 @@ def self.default_enabled
8
8
end
9
9
10
10
defsystem_prompt
11
+
examples=[
12
+
{
13
+
input: {
14
+
content:
15
+
"**Heathrow fechado**: Suspensão de voos deve continuar nos próximos dias, afirma gerente do aeroporto de Londres\n\n[details=Do site da BBC]\n\nA British Airways estimou que 85% de seus voos planejados seriam realizados no sábado, mas com atrasos em todos os voos. Às 7h GMT, a maioria das partidas havia ocorrido conforme o esperado, mas, das chegadas, nove dos primeiros 20 voos programados para aterrissar foram cancelados.\n\n[/details]",
16
+
target_locale: "en",
17
+
}.to_json,
18
+
output:
19
+
"**Heathrow Closed**: Flight Suspension Expected to Continue for the Coming Days, Says London Airport Manager\n\n[details=From the BBC website]\n\nBritish Airways estimated that 85% of its scheduled flights would operate on Saturday, but all flights were delayed. By 7:00 a.m. GMT, most departures had proceeded as expected, but of the arrivals, nine of the first 20 flights scheduled to land were canceled.\n\n[/details]",
20
+
},
21
+
{
22
+
input: {
23
+
content:
24
+
"[quote] What does the new update include? [/quote]\n\nNew Update for Minecraft Adds Underwater Temples",
25
+
target_locale: "es",
26
+
}.to_json,
27
+
output:
28
+
"[quote]¿Qué incluye la nueva actualización?[/quote]\n\nNueva actualización para Minecraft añade templos submarinos",
29
+
},
30
+
{
31
+
input: {
32
+
content:
33
+
"There has been an error in my update\n\n```ruby\napi_key = \"a quick brown fox\"\nfetch(\"https://api.example.com/data\", headers: { 'Authorization' => api_key })\n```\n\nPlease help me fix it.",
You are a highly skilled translator tasked with translating content from one language to another. Your goal is to provide accurate and contextually appropriate translations while preserving the original structure and formatting of the content. Follow these instructions strictly:
13
43
14
44
1. Preserve Markdown elements, HTML elements, or newlines. Text must be translated without altering the original formatting.
15
45
2. Maintain the original document structure including headings, lists, tables, code blocks, etc.
16
46
3. Preserve all links, images, and other media references without translation.
17
-
4. For technical terminology:
47
+
4. For technical and brand terminology:
18
48
- Provide the accepted target language term if it exists.
19
49
- If no equivalent exists, transliterate the term and include the original term in parentheses.
20
50
5. For ambiguous terms or phrases, choose the most contextually appropriate translation.
21
51
6. Ensure the translation only contains the original language and the target language.
22
52
23
53
Follow these instructions on what NOT to do:
24
-
7. Do not translate code snippets or programming language names, but ensure that any comments within the code are translated.
54
+
7. Do not translate code snippets or programming language names, but ensure that any comments within the code are translated. Code can be represented in ``` or in single ` backticks or in <code> HTML tags.
25
55
8. Do not add any content besides the translation.
56
+
9. Do not add unnecessary newlines.
57
+
58
+
Here are three examples of correct translations:
59
+
60
+
Input: #{examples[0][:input]}
61
+
Output: #{examples[0][:output]}
62
+
63
+
Input: #{examples[1][:input]}
64
+
Output: #{examples[1][:output]}
65
+
66
+
Input: #{examples[2][:input]}
67
+
Output: #{examples[2][:output]}
26
68
27
69
The text to translate will be provided in JSON format with the following structure:
28
70
{"content": "Text to translate", "target_locale": "Target language code"}
29
71
30
-
Output your translation in the following JSON format:
31
-
{"translation": "Your translated text here"}
32
-
33
-
You are being consumed via an API. Only return the translated text in the specified JSON format. Do not include any additional information or explanations.
72
+
You are being consumed via an API that expects only the translated text. Only return the translated text in the correct language. Do not add questions or explanations.
34
73
PROMPT
35
74
end
36
75
37
-
defresponse_format
38
-
[{"key"=>"translation","type"=>"string"}]
39
-
end
40
-
41
76
deftemperature
42
77
0.3
43
78
end
44
-
45
-
defexamples
46
-
[
47
-
[
48
-
{
49
-
content:
50
-
"**Heathrow fechado**: paralisação de voos deve continuar nos próximos dias, diz gestora do aeroporto de *Londres*",
51
-
target_locale: "en",
52
-
}.to_json,
53
-
{
54
-
translation:
55
-
"**Heathrow closed**: flight disruption expected to continue in coming days, says *London* airport management",
56
-
}.to_json,
57
-
],
58
-
[
59
-
{
60
-
content: "New Update for Minecraft Adds Underwater Temples",
61
-
target_locale: "es",
62
-
}.to_json,
63
-
{translation: "Nueva actualización para Minecraft añade templos submarinos"}.to_json,
You are a translation service specializing in translating short pieces of text or a few words.
13
23
These words may be things like a name, description, or title. Adhere to the following guidelines:
@@ -17,41 +27,30 @@ def system_prompt
17
27
3. Translation maintains the original meaning
18
28
4. Preserve any Markdown, HTML elements, links, parenthesis, or newlines
19
29
30
+
Here are four examples of correct translations:
31
+
32
+
Input: #{examples[0][:input]}
33
+
Output: #{examples[0][:output]}
34
+
35
+
Input: #{examples[1][:input]}
36
+
Output: #{examples[1][:output]}
37
+
38
+
Input: #{examples[2][:input]}
39
+
Output: #{examples[2][:output]}
40
+
41
+
Input: #{examples[3][:input]}
42
+
Output: #{examples[3][:output]}
43
+
20
44
The text to translate will be provided in JSON format with the following structure:
21
45
{"content": "Text to translate", "target_locale": "Target language code"}
22
46
23
-
Provide your translation in the following JSON format:
24
-
{"translation": "target_locale translation here"}
25
-
26
-
Translate the text now and provide your answer in the specified JSON format.
47
+
You are being consumed via an API that expects only the translated text. Only return the translated text in the correct language. Do not add questions or explanations.
output: "Toyota annonce une technologie de batteries révolutionnaire",
25
+
},
26
+
{
27
+
input: {
28
+
content:
29
+
"Heathrow fechado: paralisação de voos deve continuar nos próximos dias, diz gestora do aeroporto de Londres",
30
+
target_locale: "en",
31
+
}.to_json,
32
+
output:
33
+
"Heathrow closed: flight disruption expected to continue in coming days, says London airport management",
34
+
},
35
+
]
36
+
11
37
<<~PROMPT.strip
12
38
You are a translation service specializing in translating forum post titles from English to the asked target_locale. Your task is to provide accurate and contextually appropriate translations while adhering to the following guidelines:
13
39
@@ -24,53 +50,27 @@ def system_prompt
24
50
4. Adjust the translation if necessary to keep the length similar to the original title.
25
51
5. Review your translation for accuracy and naturalness in the target_locale.
26
52
53
+
Here are three examples of correct translations:
54
+
55
+
Input: #{examples[0][:input]}
56
+
Output: #{examples[0][:output]}
57
+
58
+
Input: #{examples[1][:input]}
59
+
Output: #{examples[1][:output]}
60
+
61
+
Input: #{examples[2][:input]}
62
+
Output: #{examples[2][:output]}
63
+
27
64
The text to translate will be provided in JSON format with the following structure:
28
65
{"content": "Title to translate", "target_locale": "Target language code"}
29
66
30
-
Provide your translation in the following JSON format:
Remember to keep proper nouns like "Minecraft" and "Toyota" in their original form. Translate the title now and provide your answer in the specified JSON format.
67
+
Remember to keep proper nouns like "Minecraft" and "Toyota" in their original form. You are being consumed via an API that expects only the translated title. Only return the translated title in the correct language. Do not add questions or explanations.
34
68
PROMPT
35
69
end
36
70
37
-
defresponse_format
38
-
[{"key"=>"translation","type"=>"string"}]
39
-
end
40
-
41
71
deftemperature
42
72
0.3
43
73
end
44
-
45
-
defexamples
46
-
[
47
-
[
48
-
{
49
-
content: "New Update for Minecraft Adds Underwater Temples",
50
-
target_locale: "es",
51
-
}.to_json,
52
-
{translation: "Nueva actualización para Minecraft añade templos submarinos"}.to_json,
0 commit comments