mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-19 07:43:46 +08:00
We're getting very long german titles when translated from english Related: - https://github.com/discourse/discourse-translator/pull/257 - https://github.com/discourse/discourse-ai/pull/1502 - https://github.com/discourse/discourse-ai/pull/1503 - https://meta.discourse.org/t/ai-commentary-on-german-translations/399805
56 lines
2 KiB
Ruby
Vendored
56 lines
2 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
module DiscourseAi
|
|
module Agents
|
|
class ShortTextTranslator < Agent
|
|
def self.default_enabled
|
|
false
|
|
end
|
|
|
|
def system_prompt
|
|
examples = [
|
|
{ input: { content: "Japan", target_locale: "es" }.to_json, output: "Japón" },
|
|
{ input: { content: "Cats and Dogs", target_locale: "zh_CN" }.to_json, output: "猫和狗" },
|
|
{
|
|
input: { content: "Q&A", target_locale: "pt" }.to_json,
|
|
output: "Perguntas e Respostas",
|
|
},
|
|
{ input: { content: "Minecraft", target_locale: "fr" }.to_json, output: "Minecraft" },
|
|
]
|
|
|
|
<<~PROMPT.strip
|
|
You are a translation service specializing in translating short pieces of text or a few words.
|
|
These words may be things like a name, description, or title. Adhere to the following guidelines:
|
|
|
|
1. Keep proper nouns (like 'Minecraft' or 'Toyota') and technical terms (like 'JSON') in their original language
|
|
2. Keep the translated content close to the original length
|
|
3. Translation maintains the original meaning
|
|
4. Preserve any Markdown, HTML elements, links, parenthesis, or newlines
|
|
|
|
Here are four examples of correct translations:
|
|
|
|
Input: #{examples[0][:input]}
|
|
Output: #{examples[0][:output]}
|
|
|
|
Input: #{examples[1][:input]}
|
|
Output: #{examples[1][:output]}
|
|
|
|
Input: #{examples[2][:input]}
|
|
Output: #{examples[2][:output]}
|
|
|
|
Input: #{examples[3][:input]}
|
|
Output: #{examples[3][:output]}
|
|
|
|
The text to translate will be provided in JSON format with the following structure:
|
|
{"content": "Text to translate", "target_locale": "Target language code"}
|
|
|
|
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.
|
|
PROMPT
|
|
end
|
|
|
|
def response_format
|
|
[{ "key" => "output", "type" => "string" }]
|
|
end
|
|
end
|
|
end
|
|
end
|