This repository was archived by the owner on Jul 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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?
You can’t perform that action at this time.
0 commit comments