Skip to content

Commit fbcc8e4

Browse files
authored
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.
1 parent 6b7d7c1 commit fbcc8e4

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

config/locales/client.en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ en:
113113
flag_post:
114114
label: "Flag post"
115115
description: "Flags post (either as spam or for review)"
116+
include_personal_messages:
117+
label: "Include personal messages"
118+
description: "Also scan and triage personal messages"
116119
model:
117120
label: "Model"
118121
description: "Language model used for triage"

discourse_automation/llm_triage.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
field :tags, component: :tags
2323
field :hide_topic, component: :boolean
2424
field :flag_post, component: :boolean
25+
field :include_personal_messages, component: :boolean
2526
field :flag_type,
2627
component: :choices,
2728
required: false,
@@ -54,6 +55,11 @@
5455

5556
max_post_tokens = nil if max_post_tokens <= 0
5657

58+
if post.topic.private_message?
59+
include_personal_messages = fields.dig("include_personal_messages", "value")
60+
next if !include_personal_messages
61+
end
62+
5763
begin
5864
RateLimiter.new(
5965
Discourse.system_user,

spec/lib/discourse_automation/llm_triage_spec.rb

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
describe DiscourseAi::Automation::LlmTriage do
66
fab!(:category)
77
fab!(:reply_user) { Fabricate(:user) }
8+
fab!(:personal_message) { Fabricate(:private_message_topic) }
9+
let(:canned_reply_text) { "Hello, this is a reply" }
810

911
let(:automation) { Fabricate(:automation, script: "llm_triage", enabled: true) }
1012

@@ -30,7 +32,7 @@ def add_automation_field(name, value, type: "text")
3032
add_automation_field("tags", %w[aaa bbb], type: "tags")
3133
add_automation_field("hide_topic", true, type: "boolean")
3234
add_automation_field("flag_post", true, type: "boolean")
33-
add_automation_field("canned_reply", "Yo this is a reply")
35+
add_automation_field("canned_reply", canned_reply_text)
3436
add_automation_field("canned_reply_user", reply_user.username, type: "user")
3537
add_automation_field("max_post_tokens", 100)
3638
end
@@ -63,7 +65,7 @@ def add_automation_field(name, value, type: "text")
6365
expect(topic.tags.pluck(:name)).to contain_exactly("aaa", "bbb")
6466
expect(topic.visible).to eq(false)
6567
reply = topic.posts.order(:post_number).last
66-
expect(reply.raw).to eq("Yo this is a reply")
68+
expect(reply.raw).to eq(canned_reply_text)
6769
expect(reply.user.id).to eq(reply_user.id)
6870

6971
ai_log = AiApiAuditLog.order("id desc").first
@@ -79,6 +81,30 @@ def add_automation_field(name, value, type: "text")
7981
expect(count).to be > (50)
8082
end
8183

84+
it "does not triage PMs by default" do
85+
post = Fabricate(:post, topic: personal_message)
86+
automation.running_in_background!
87+
automation.trigger!({ "post" => post })
88+
89+
# nothing should happen, no classification, its a PM
90+
end
91+
92+
it "will triage PMs if automation allows it" do
93+
# needs to be admin or it will not be able to just step in to
94+
# PM
95+
reply_user.update!(admin: true)
96+
add_automation_field("include_personal_messages", true, type: :boolean)
97+
post = Fabricate(:post, topic: personal_message)
98+
99+
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
100+
automation.running_in_background!
101+
automation.trigger!({ "post" => post })
102+
end
103+
104+
last_post = post.topic.reload.posts.order(:post_number).last
105+
expect(last_post.raw).to eq(canned_reply_text)
106+
end
107+
82108
it "does not reply to the canned_reply_user" do
83109
post = Fabricate(:post, user: reply_user)
84110

0 commit comments

Comments
 (0)