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
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ inherit_gem:
rubocop-discourse: stree-compat.yml
RSpec/NamedSubject:
Enabled: false

Style/GlobalVars:
AllowedVariables: [$prometheus_client]
7 changes: 7 additions & 0 deletions about.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"tests": {
"requiredPlugins": [
"https://github.com/discourse/discourse-prometheus"
]
}
}
29 changes: 29 additions & 0 deletions lib/ai_moderation/spam_metric.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# frozen_string_literal: true

module DiscourseAi
module AiModeration
class SpamMetric
def self.update(new_status, reviewable)
ai_spam_log = AiSpamLog.find_by(reviewable:)
return if ai_spam_log.nil?

increment("scanned")
increment("is_spam") if new_status == :approved && ai_spam_log.is_spam
increment("false_positive") if new_status == :rejected && ai_spam_log.is_spam
increment("false_negative") if new_status == :rejected && !ai_spam_log.is_spam
end

private

def self.increment(type, value = 1)
metric = ::DiscoursePrometheus::InternalMetric::Custom.new
metric.name = "discourse_ai_spam_detection"
metric.type = "Counter"
metric.description = "AI spam scanning statistics"
metric.labels = { db: RailsMultisite::ConnectionManagement.current_db, type: }
metric.value = value
$prometheus_client.send_json(metric.to_h)
end
end
end
end
3 changes: 3 additions & 0 deletions plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ def self.public_asset_path(name)

on(:reviewable_transitioned_to) do |new_status, reviewable|
ModelAccuracy.adjust_model_accuracy(new_status, reviewable)
if DiscourseAi::AiModeration::SpamScanner.enabled?
DiscourseAi::AiModeration::SpamMetric.update(new_status, reviewable)
end
end

if Rails.env.test?
Expand Down
Loading