Skip to content

A platform for community discussion. Free, open, simple.

1.5 KB
Raw Blame
# frozen_string_literal: true

module DiscourseAi
  module Agents
    class Translator < Agent
      def self.default_enabled
        false
      end

      def thinking_effort
        "none"
      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
    end
  end
end