FEATURE: Skip PM scanning in LLM triage by default (#966)

Usually people do not want to scan personal messages. Sometimes
they may. In that case they can enable triage on personal messages.
This commit is contained in:
Sam 2024-11-28 09:25:29 +11:00 committed by GitHub
parent 6b7d7c1179
commit fbcc8e493a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 37 additions and 2 deletions

View File

@ -113,6 +113,9 @@ en:
flag_post: flag_post:
label: "Flag post" label: "Flag post"
description: "Flags post (either as spam or for review)" description: "Flags post (either as spam or for review)"
include_personal_messages:
label: "Include personal messages"
description: "Also scan and triage personal messages"
model: model:
label: "Model" label: "Model"
description: "Language model used for triage" description: "Language model used for triage"

View File

@ -22,6 +22,7 @@ if defined?(DiscourseAutomation)
field :tags, component: :tags field :tags, component: :tags
field :hide_topic, component: :boolean field :hide_topic, component: :boolean
field :flag_post, component: :boolean field :flag_post, component: :boolean
field :include_personal_messages, component: :boolean
field :flag_type, field :flag_type,
component: :choices, component: :choices,
required: false, required: false,
@ -54,6 +55,11 @@ if defined?(DiscourseAutomation)
max_post_tokens = nil if max_post_tokens <= 0 max_post_tokens = nil if max_post_tokens <= 0
if post.topic.private_message?
include_personal_messages = fields.dig("include_personal_messages", "value")
next if !include_personal_messages
end
begin begin
RateLimiter.new( RateLimiter.new(
Discourse.system_user, Discourse.system_user,

View File

@ -5,6 +5,8 @@ return if !defined?(DiscourseAutomation)
describe DiscourseAi::Automation::LlmTriage do describe DiscourseAi::Automation::LlmTriage do
fab!(:category) fab!(:category)
fab!(:reply_user) { Fabricate(:user) } fab!(:reply_user) { Fabricate(:user) }
fab!(:personal_message) { Fabricate(:private_message_topic) }
let(:canned_reply_text) { "Hello, this is a reply" }
let(:automation) { Fabricate(:automation, script: "llm_triage", enabled: true) } let(:automation) { Fabricate(:automation, script: "llm_triage", enabled: true) }
@ -30,7 +32,7 @@ describe DiscourseAi::Automation::LlmTriage do
add_automation_field("tags", %w[aaa bbb], type: "tags") add_automation_field("tags", %w[aaa bbb], type: "tags")
add_automation_field("hide_topic", true, type: "boolean") add_automation_field("hide_topic", true, type: "boolean")
add_automation_field("flag_post", true, type: "boolean") add_automation_field("flag_post", true, type: "boolean")
add_automation_field("canned_reply", "Yo this is a reply") add_automation_field("canned_reply", canned_reply_text)
add_automation_field("canned_reply_user", reply_user.username, type: "user") add_automation_field("canned_reply_user", reply_user.username, type: "user")
add_automation_field("max_post_tokens", 100) add_automation_field("max_post_tokens", 100)
end end
@ -63,7 +65,7 @@ describe DiscourseAi::Automation::LlmTriage do
expect(topic.tags.pluck(:name)).to contain_exactly("aaa", "bbb") expect(topic.tags.pluck(:name)).to contain_exactly("aaa", "bbb")
expect(topic.visible).to eq(false) expect(topic.visible).to eq(false)
reply = topic.posts.order(:post_number).last reply = topic.posts.order(:post_number).last
expect(reply.raw).to eq("Yo this is a reply") expect(reply.raw).to eq(canned_reply_text)
expect(reply.user.id).to eq(reply_user.id) expect(reply.user.id).to eq(reply_user.id)
ai_log = AiApiAuditLog.order("id desc").first ai_log = AiApiAuditLog.order("id desc").first
@ -79,6 +81,30 @@ describe DiscourseAi::Automation::LlmTriage do
expect(count).to be > (50) expect(count).to be > (50)
end end
it "does not triage PMs by default" do
post = Fabricate(:post, topic: personal_message)
automation.running_in_background!
automation.trigger!({ "post" => post })
# nothing should happen, no classification, its a PM
end
it "will triage PMs if automation allows it" do
# needs to be admin or it will not be able to just step in to
# PM
reply_user.update!(admin: true)
add_automation_field("include_personal_messages", true, type: :boolean)
post = Fabricate(:post, topic: personal_message)
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
automation.running_in_background!
automation.trigger!({ "post" => post })
end
last_post = post.topic.reload.posts.order(:post_number).last
expect(last_post.raw).to eq(canned_reply_text)
end
it "does not reply to the canned_reply_user" do it "does not reply to the canned_reply_user" do
post = Fabricate(:post, user: reply_user) post = Fabricate(:post, user: reply_user)