discourse-ai/app/jobs/regular/toxicity_classify_chat_mess...

19 lines
508 B
Ruby
Raw Normal View History

2023-02-22 18:46:53 -05:00
# frozen_string_literal: true
module ::Jobs
class ToxicityClassifyChatMessage < ::Jobs::Base
2023-02-22 18:46:53 -05:00
def execute(args)
return unless SiteSetting.ai_toxicity_enabled
return if (chat_message_id = args[:chat_message_id]).blank?
2023-02-22 18:46:53 -05:00
2023-03-17 10:15:38 -04:00
chat_message = ::Chat::Message.find_by(id: chat_message_id)
2023-02-22 18:46:53 -05:00
return if chat_message&.message.blank?
DiscourseAi::ChatMessageClassificator.new(
DiscourseAi::Toxicity::ToxicityClassification.new,
).classify!(chat_message)
2023-02-22 18:46:53 -05:00
end
end
end