Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit f51bfdc

Browse files
committed
DEV: Expose AI spam scanning metrics
1 parent 7957796 commit f51bfdc

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

lib/ai_moderation/spam_metric.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
module DiscourseAi
4+
module AiModeration
5+
class SpamMetric
6+
def self.update(new_status, reviewable)
7+
ai_spam_log = AiSpamLog.find_by(reviewable:)
8+
return if ai_spam_log.nil?
9+
10+
increment("scanned")
11+
increment("is_spam") if new_status == :approved && ai_spam_log.is_spam
12+
increment("false_positive") if new_status == :rejected && ai_spam_log.is_spam
13+
increment("false_negative") if new_status == :rejected && !ai_spam_log.is_spam
14+
end
15+
16+
private
17+
18+
def self.increment(type, value = 1)
19+
metric = DiscoursePrometheus::InternalMetric::Custom.new
20+
metric.name = "discourse_ai_spam_detection"
21+
metric.type = "Counter"
22+
metric.description = "AI spam scanning statistics"
23+
metric.labels = { db: RailsMultisite::ConnectionManagement.current_db, type: }
24+
metric.value = value
25+
$prometheus_client.send_json(metric.to_h)
26+
end
27+
end
28+
end
29+
end

plugin.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ def self.public_asset_path(name)
8383

8484
on(:reviewable_transitioned_to) do |new_status, reviewable|
8585
ModelAccuracy.adjust_model_accuracy(new_status, reviewable)
86+
if DiscourseAi::AiModeration::SpamScanner.enabled?
87+
DiscourseAi::AiModeration::SpamMetric.update(new_status, reviewable)
88+
end
8689
end
8790

8891
if Rails.env.test?

0 commit comments

Comments
 (0)