Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 35 additions & 20 deletions assets/javascripts/discourse/components/ai-features-list.gjs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export default class AiFeaturesList extends Component {
});
}

@action
isSpamModule(aModule) {
return aModule.module_name === "spam";
}

@action
hasGroups(feature) {
return this.groupList(feature).length > 0;
Expand Down Expand Up @@ -101,12 +106,20 @@ export default class AiFeaturesList extends Component {
<h3>{{i18n
(concat "discourse_ai.features." module.module_name ".name")
}}</h3>
<DButton
class="edit"
@label="discourse_ai.features.edit"
@route="adminPlugins.show.discourse-ai-features.edit"
@routeModels={{module.id}}
/>
{{#if (this.isSpamModule module)}}
<DButton
class="edit"
@label="discourse_ai.features.edit"
@route="adminPlugins.show.discourse-ai-spam"
/>
{{else}}
<DButton
class="edit"
@label="discourse_ai.features.edit"
@route="adminPlugins.show.discourse-ai-features.edit"
@routeModels={{module.id}}
/>
{{/if}}
</div>
<div>{{i18n
(concat
Expand Down Expand Up @@ -181,20 +194,22 @@ export default class AiFeaturesList extends Component {
{{i18n "discourse_ai.features.no_llm"}}
{{/if}}
</div>
{{#if feature.personas}}
<div class="ai-feature-card__groups">
<span>{{i18n "discourse_ai.features.groups"}}</span>
{{#if (this.hasGroups feature)}}
<ul class="ai-feature-card__item-groups">
{{#each (this.groupList feature) as |group|}}
<li>{{group.name}}</li>
{{/each}}
</ul>
{{else}}
{{i18n "discourse_ai.features.no_groups"}}
{{/if}}
</div>
{{/if}}
{{#unless (this.isSpamModule module)}}
{{#if feature.personas}}
<div class="ai-feature-card__groups">
<span>{{i18n "discourse_ai.features.groups"}}</span>
{{#if (this.hasGroups feature)}}
<ul class="ai-feature-card__item-groups">
{{#each (this.groupList feature) as |group|}}
<li>{{group.name}}</li>
{{/each}}
</ul>
{{else}}
{{i18n "discourse_ai.features.no_groups"}}
{{/if}}
</div>
{{/if}}
{{/unless}}
</div>
</div>
{{/each}}
Expand Down
7 changes: 6 additions & 1 deletion config/locales/client.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ en:

ai_helper:
name: "Helper"
description: "Assists users in community interaction, such as creating topics, writing posts, and reading content."
description: "Assists users in community interaction, such as creating topics, writing posts, and reading content"
proofread: Proofread text
title_suggestions: "Suggest titles"
explain: "Explain"
Expand All @@ -248,6 +248,11 @@ en:
post_raw_translator: "Post raw translator"
topic_title_translator: "Topic title translator"
short_text_translator: "Short text translator"

spam:
name: "Spam"
description: "Identifies potential spam using the selected LLM and flags it for site moderators to inspect in the review queue"
inspect_posts: "Inspect posts"

modals:
select_option: "Select an option..."
Expand Down
14 changes: 14 additions & 0 deletions lib/configuration/feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ def bot_features
]
end

def spam_features
feature_cache[:spam] ||= [
new(
"inspect_posts",
nil,
DiscourseAi::Configuration::Module::SPAM_ID,
DiscourseAi::Configuration::Module::SPAM,
persona_ids_lookup: -> { [AiModerationSetting.spam&.ai_persona_id].compact },
llm_models_lookup: -> { [AiModerationSetting.spam&.llm_model].compact },
),
]
end

def lookup_bot_persona_ids
AiPersona
.where(enabled: true)
Expand Down Expand Up @@ -182,6 +195,7 @@ def all
ai_helper_features,
translation_features,
bot_features,
spam_features,
].flatten
end

Expand Down
28 changes: 19 additions & 9 deletions lib/configuration/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class Module
AI_HELPER = "ai_helper"
TRANSLATION = "translation"
BOT = "bot"
SPAM = "spam"

NAMES = [SUMMARIZATION, SEARCH, DISCORD, INFERENCE, AI_HELPER, TRANSLATION, BOT].freeze
NAMES = [SUMMARIZATION, SEARCH, DISCORD, INFERENCE, AI_HELPER, TRANSLATION, BOT, SPAM].freeze

SUMMARIZATION_ID = 1
SEARCH_ID = 2
Expand All @@ -20,53 +21,60 @@ class Module
AI_HELPER_ID = 5
TRANSLATION_ID = 6
BOT_ID = 7
SPAM_ID = 8

class << self
def all
[
new(
SUMMARIZATION_ID,
SUMMARIZATION,
"ai_summarization_enabled",
enabled_by_setting: "ai_summarization_enabled",
features: DiscourseAi::Configuration::Feature.summarization_features,
),
new(
SEARCH_ID,
SEARCH,
"ai_bot_enabled",
enabled_by_setting: "ai_bot_enabled",
features: DiscourseAi::Configuration::Feature.search_features,
extra_check: -> { SiteSetting.ai_bot_discover_persona.present? },
),
new(
DISCORD_ID,
DISCORD,
"ai_discord_search_enabled",
enabled_by_setting: "ai_discord_search_enabled",
features: DiscourseAi::Configuration::Feature.discord_features,
),
new(
INFERENCE_ID,
INFERENCE,
"inferred_concepts_enabled",
enabled_by_setting: "inferred_concepts_enabled",
features: DiscourseAi::Configuration::Feature.inference_features,
),
new(
AI_HELPER_ID,
AI_HELPER,
"ai_helper_enabled",
enabled_by_setting: "ai_helper_enabled",
features: DiscourseAi::Configuration::Feature.ai_helper_features,
),
new(
TRANSLATION_ID,
TRANSLATION,
"ai_translation_enabled",
enabled_by_setting: "ai_translation_enabled",
features: DiscourseAi::Configuration::Feature.translation_features,
),
new(
BOT_ID,
BOT,
"ai_bot_enabled",
enabled_by_setting: "ai_bot_enabled",
features: DiscourseAi::Configuration::Feature.bot_features,
),
new(
SPAM_ID,
SPAM,
enabled_by_setting: "ai_spam_detection_enabled",
features: DiscourseAi::Configuration::Feature.spam_features,
),
]
end

Expand All @@ -75,7 +83,7 @@ def find_by(id:)
end
end

def initialize(id, name, enabled_by_setting, features: [], extra_check: nil)
def initialize(id, name, enabled_by_setting: nil, features: [], extra_check: nil)
@id = id
@name = name
@enabled_by_setting = enabled_by_setting
Expand All @@ -86,6 +94,8 @@ def initialize(id, name, enabled_by_setting, features: [], extra_check: nil)
attr_reader :id, :name, :enabled_by_setting, :features

def enabled?
return @extra_check.call if enabled_by_setting.blank? && @extra_check.present?

enabled_setting = SiteSetting.get(enabled_by_setting)

if @extra_check
Expand Down
2 changes: 1 addition & 1 deletion spec/requests/admin/ai_features_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
get "/admin/plugins/discourse-ai/ai-features.json"

expect(response.status).to eq(200)
expect(response.parsed_body["ai_features"].count).to eq(7)
expect(response.parsed_body["ai_features"].count).to eq(8)
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/system/admin_ai_features_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
ai_features_page.toggle_unconfigured

# this changes as we add more AI features
expect(ai_features_page).to have_listed_modules(6)
expect(ai_features_page).to have_listed_modules(7)
end

it "lists the persona used for the corresponding AI feature" do
Expand Down
Loading