A platform for community discussion. Free, open, simple.
FEATURE: Allow bot content to be AI translated (#37291)
Natalie Tay6bcffe2b06ac
diff --git a/plugins/discourse-ai/config/locales/server.en.yml b/plugins/discourse-ai/config/locales/server.en.ymlindex f601f7bf742..5395a2eb124 100644--- a/plugins/discourse-ai/config/locales/server.en.yml+++ b/plugins/discourse-ai/config/locales/server.en.yml@@ -155,6 +155,7 @@ en:ai_translation_enabled: "Enable the AI translation feature"ai_translation_model: "The model to use for translation. This model must support translation. Personas can override this setting."ai_translation_backfill_limit_to_public_content: "When enabled, only content in public categories will be translated. When disabled, content in group PMs and private categories will also be sent for translation."+ ai_translation_include_bot_content: "When enabled, content written by bots (user IDs below 0) will also be sent for translation."ai_translation_max_post_length: "The maximum number of characters for a post to be translated. Posts longer than this will not be translated."ai_translation_backfill_max_age_days: "The maximum age of a post and topic to be translated. Posts and topics older than this will not be translated. 0 disables backfilling, but will not disable translation of new posts."ai_translation_backfill_hourly_rate: "The number of posts and topics to translate per hour during backfill operations. Set to 0 to disable automatic backfilling of translations for existing content."diff --git a/plugins/discourse-ai/config/settings.yml b/plugins/discourse-ai/config/settings.ymlindex aa4049126c5..8f6b5c2c33e 100644--- a/plugins/discourse-ai/config/settings.yml+++ b/plugins/discourse-ai/config/settings.yml@@ -522,6 +522,10 @@ discourse_ai:default: trueclient: falsearea: "ai-features/translation"+ ai_translation_include_bot_content:+ default: false+ client: false+ area: "ai-features/translation"ai_translation_max_post_length:default: 10000client: falsediff --git a/plugins/discourse-ai/lib/translation/post_candidates.rb b/plugins/discourse-ai/lib/translation/post_candidates.rbindex b715b62c1d7..1bcc36b7ce7 100644--- a/plugins/discourse-ai/lib/translation/post_candidates.rb+++ b/plugins/discourse-ai/lib/translation/post_candidates.rb@@ -23,10 +23,12 @@ module DiscourseAiSiteSetting.ai_translation_backfill_max_age_days.days.ago,).where(deleted_at: nil)- .where("posts.user_id > 0").where.not(raw: [nil, ""]).where("LENGTH(posts.raw) <= ?", SiteSetting.ai_translation_max_post_length)+ posts =+ posts.where("posts.user_id > 0") unless SiteSetting.ai_translation_include_bot_content+posts = posts.joins(:topic)if SiteSetting.ai_translation_backfill_limit_to_public_content# exclude all PMsdiff --git a/plugins/discourse-ai/lib/translation/topic_candidates.rb b/plugins/discourse-ai/lib/translation/topic_candidates.rbindex a71c67cebcb..67447826f5a 100644--- a/plugins/discourse-ai/lib/translation/topic_candidates.rb+++ b/plugins/discourse-ai/lib/translation/topic_candidates.rb@@ -9,13 +9,13 @@ module DiscourseAi# including those without locale detected yet.def self.gettopics =- Topic- .where(- "topics.created_at > ?",- SiteSetting.ai_translation_backfill_max_age_days.days.ago,- )- .where(deleted_at: nil)- .where("topics.user_id > 0")+ Topic.where(+ "topics.created_at > ?",+ SiteSetting.ai_translation_backfill_max_age_days.days.ago,+ ).where(deleted_at: nil)++ topics =+ topics.where("topics.user_id > 0") unless SiteSetting.ai_translation_include_bot_contentif SiteSetting.ai_translation_backfill_limit_to_public_content# exclude all PMsdiff --git a/plugins/discourse-ai/spec/lib/translation/post_candidates_spec.rb b/plugins/discourse-ai/spec/lib/translation/post_candidates_spec.rbindex 0bf1ebcc526..8cedfe2f2d0 100644--- a/plugins/discourse-ai/spec/lib/translation/post_candidates_spec.rb+++ b/plugins/discourse-ai/spec/lib/translation/post_candidates_spec.rb@@ -8,6 +8,18 @@ describe DiscourseAi::Translation::PostCandidates doexpect(DiscourseAi::Translation::PostCandidates.get).not_to include(post)end+ describe "SiteSetting.ai_translation_include_bot_content" do+ it "includes bot posts when enabled" do+ SiteSetting.ai_translation_include_bot_content = true+ bot_post = Fabricate(:post, user: Discourse.system_user)+ regular_post = Fabricate(:post)++ posts = DiscourseAi::Translation::PostCandidates.get+ expect(posts).to include(bot_post)+ expect(posts).to include(regular_post)+ end+ end+it "does not return posts older than ai_translation_backfill_max_age_days" dopost =Fabricate(diff --git a/plugins/discourse-ai/spec/lib/translation/topic_candidates_spec.rb b/plugins/discourse-ai/spec/lib/translation/topic_candidates_spec.rbindex 9e5f0673dd4..b05f25eb59e 100644--- a/plugins/discourse-ai/spec/lib/translation/topic_candidates_spec.rb+++ b/plugins/discourse-ai/spec/lib/translation/topic_candidates_spec.rb@@ -8,6 +8,18 @@ describe DiscourseAi::Translation::TopicCandidates doexpect(DiscourseAi::Translation::TopicCandidates.get).not_to include(topic)end+ describe "SiteSetting.ai_translation_include_bot_content" do+ it "includes bot topics when enabled" do+ SiteSetting.ai_translation_include_bot_content = true+ bot_topic = Fabricate(:topic, user: Discourse.system_user)+ regular_topic = Fabricate(:topic)++ topics = DiscourseAi::Translation::TopicCandidates.get+ expect(topics).to include(bot_topic)+ expect(topics).to include(regular_topic)+ end+ end+it "does not return topics older than ai_translation_backfill_max_age_days" dotopic =Fabricate(