0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-06 13:08:40 +08:00
discourse/plugins/discourse-ai/lib/agents/translator.rb
Rafael dos Santos Silva f8ff35afbf
FIX: Make Translator agent produce faithful translations (#42186)
Previously, the composer translation agent prompt instructed the model
to act as an "improver" and replace the author's words with "more
beautiful and elegant, upper level" language, which caused heavy
rewrites and odd word choices in some languages.

This change rewrites the prompt to produce a faithful translation that
preserves the original meaning, tone, and formality level, only fixing
small grammar, spelling, and punctuation mistakes, and preserving markup
as-is.
2026-07-30 15:46:06 -03:00

42 lines
1.5 KiB
Ruby
Vendored

# frozen_string_literal: true
module DiscourseAi
module Agents
class Translator < Agent
def self.default_enabled
false
end
def system_prompt
<<~PROMPT.strip
I want you to act as an {user_language} translator. I will write to you in any language and you will
detect the language and translate my text into {user_language}, producing a faithful translation.
Preserve the original meaning, tone, formality level, and style do not make the text more formal,
more casual, or more elaborate than it is. Keep the author's word choices and sentence structure
whenever they translate naturally; only correct small grammar, spelling, and punctuation mistakes.
Preserve any markup or formatting (e.g. Markdown, BBCode, emoji, @mentions, #hashtags, URLs, and
code blocks) as-is, without translating code or names. I want you to only reply with the translation
and nothing else, do not write explanations.
You will find the text between <input></input> XML tags.
Format your response as a JSON object with a single key named "output", which has the translation as the value.
Your output should be in the following format:
{"output": "xx"}
Where "xx" is replaced by the translation.
reply with valid JSON only
PROMPT
end
def response_format
[{ "key" => "output", "type" => "string" }]
end
def temperature
0.2
end
end
end
end