mirror of
https://github.com/discourse/discourse-ai.git
synced 2025-03-06 17:30:20 +00:00
FEATURE: Triage rule can skip posts created via email (#775)
This commit is contained in:
parent
1b209f5fb1
commit
6af415f7f0
@ -99,6 +99,9 @@ en:
|
|||||||
model:
|
model:
|
||||||
label: "Model"
|
label: "Model"
|
||||||
description: "Language model used for triage"
|
description: "Language model used for triage"
|
||||||
|
skip_via_email:
|
||||||
|
label: "Skip via email"
|
||||||
|
description: "Don't triage posts created via email"
|
||||||
|
|
||||||
discourse_ai:
|
discourse_ai:
|
||||||
title: "AI"
|
title: "AI"
|
||||||
|
@ -19,6 +19,7 @@ if defined?(DiscourseAutomation)
|
|||||||
}
|
}
|
||||||
field :category, component: :category
|
field :category, component: :category
|
||||||
field :tags, component: :tags
|
field :tags, component: :tags
|
||||||
|
field :skip_via_email, component: :boolean
|
||||||
field :hide_topic, component: :boolean
|
field :hide_topic, component: :boolean
|
||||||
field :flag_post, component: :boolean
|
field :flag_post, component: :boolean
|
||||||
field :canned_reply, component: :message
|
field :canned_reply, component: :message
|
||||||
@ -42,6 +43,9 @@ if defined?(DiscourseAutomation)
|
|||||||
hide_topic = fields.dig("hide_topic", "value")
|
hide_topic = fields.dig("hide_topic", "value")
|
||||||
flag_post = fields.dig("flag_post", "value")
|
flag_post = fields.dig("flag_post", "value")
|
||||||
|
|
||||||
|
skip_via_email = fields.dig("skip_via_email", "value")
|
||||||
|
next if skip_via_email && post.via_email?
|
||||||
|
|
||||||
begin
|
begin
|
||||||
RateLimiter.new(
|
RateLimiter.new(
|
||||||
Discourse.system_user,
|
Discourse.system_user,
|
||||||
|
@ -62,4 +62,38 @@ describe DiscourseAi::Automation::LlmTriage do
|
|||||||
last_post = post.topic.reload.posts.order(:post_number).last
|
last_post = post.topic.reload.posts.order(:post_number).last
|
||||||
expect(last_post.raw).to eq post.raw
|
expect(last_post.raw).to eq post.raw
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "posts created via email" do
|
||||||
|
fab!(:email_post) { Fabricate(:post_via_email) }
|
||||||
|
|
||||||
|
context "when skip_via_email is enabled" do
|
||||||
|
before { add_automation_field("skip_via_email", true, type: "boolean") }
|
||||||
|
|
||||||
|
it "does nothing" do
|
||||||
|
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
||||||
|
automation.running_in_background!
|
||||||
|
automation.trigger!({ "post" => email_post })
|
||||||
|
end
|
||||||
|
|
||||||
|
reviewable = ReviewablePost.find_by(target: email_post)
|
||||||
|
|
||||||
|
expect(reviewable).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "when skip_via_email is disabled" do
|
||||||
|
before { add_automation_field("skip_via_email", false, type: "boolean") }
|
||||||
|
|
||||||
|
it "flags the post" do
|
||||||
|
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
||||||
|
automation.running_in_background!
|
||||||
|
automation.trigger!({ "post" => email_post })
|
||||||
|
end
|
||||||
|
|
||||||
|
reviewable = ReviewablePost.find_by(target: email_post)
|
||||||
|
|
||||||
|
expect(reviewable).to be_present
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -4,19 +4,15 @@ describe DiscourseAi::Automation::LlmTriage do
|
|||||||
fab!(:llm_model)
|
fab!(:llm_model)
|
||||||
|
|
||||||
def triage(**args)
|
def triage(**args)
|
||||||
DiscourseAi::Automation::LlmTriage.handle(**args)
|
rule_args = { model: "custom:#{llm_model.id}", automation: nil, system_prompt: "test" }.merge(
|
||||||
|
args,
|
||||||
|
)
|
||||||
|
DiscourseAi::Automation::LlmTriage.handle(**rule_args)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does nothing if it does not pass triage" do
|
it "does nothing if it does not pass triage" do
|
||||||
DiscourseAi::Completions::Llm.with_prepared_responses(["good"]) do
|
DiscourseAi::Completions::Llm.with_prepared_responses(["good"]) do
|
||||||
triage(
|
triage(post: post, hide_topic: true, search_for_text: "bad")
|
||||||
post: post,
|
|
||||||
model: "custom:#{llm_model.id}",
|
|
||||||
hide_topic: true,
|
|
||||||
system_prompt: "test %%POST%%",
|
|
||||||
search_for_text: "bad",
|
|
||||||
automation: nil,
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(post.topic.reload.visible).to eq(true)
|
expect(post.topic.reload.visible).to eq(true)
|
||||||
@ -24,14 +20,7 @@ describe DiscourseAi::Automation::LlmTriage do
|
|||||||
|
|
||||||
it "can hide topics on triage" do
|
it "can hide topics on triage" do
|
||||||
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
||||||
triage(
|
triage(post: post, hide_topic: true, search_for_text: "bad")
|
||||||
post: post,
|
|
||||||
model: "custom:#{llm_model.id}",
|
|
||||||
hide_topic: true,
|
|
||||||
system_prompt: "test %%POST%%",
|
|
||||||
search_for_text: "bad",
|
|
||||||
automation: nil,
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(post.topic.reload.visible).to eq(false)
|
expect(post.topic.reload.visible).to eq(false)
|
||||||
@ -41,14 +30,7 @@ describe DiscourseAi::Automation::LlmTriage do
|
|||||||
category = Fabricate(:category)
|
category = Fabricate(:category)
|
||||||
|
|
||||||
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
||||||
triage(
|
triage(post: post, category_id: category.id, search_for_text: "bad")
|
||||||
post: post,
|
|
||||||
model: "custom:#{llm_model.id}",
|
|
||||||
category_id: category.id,
|
|
||||||
system_prompt: "test %%POST%%",
|
|
||||||
search_for_text: "bad",
|
|
||||||
automation: nil,
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
expect(post.topic.reload.category_id).to eq(category.id)
|
expect(post.topic.reload.category_id).to eq(category.id)
|
||||||
@ -59,12 +41,9 @@ describe DiscourseAi::Automation::LlmTriage do
|
|||||||
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
||||||
triage(
|
triage(
|
||||||
post: post,
|
post: post,
|
||||||
model: "custom:#{llm_model.id}",
|
|
||||||
system_prompt: "test %%POST%%",
|
|
||||||
search_for_text: "bad",
|
search_for_text: "bad",
|
||||||
canned_reply: "test canned reply 123",
|
canned_reply: "test canned reply 123",
|
||||||
canned_reply_user: user.username,
|
canned_reply_user: user.username,
|
||||||
automation: nil,
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -76,14 +55,7 @@ describe DiscourseAi::Automation::LlmTriage do
|
|||||||
|
|
||||||
it "can add posts to the review queue" do
|
it "can add posts to the review queue" do
|
||||||
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
||||||
triage(
|
triage(post: post, search_for_text: "bad", flag_post: true)
|
||||||
post: post,
|
|
||||||
model: "custom:#{llm_model.id}",
|
|
||||||
system_prompt: "test %%POST%%",
|
|
||||||
search_for_text: "bad",
|
|
||||||
flag_post: true,
|
|
||||||
automation: nil,
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
reviewable = ReviewablePost.last
|
reviewable = ReviewablePost.last
|
||||||
@ -94,14 +66,7 @@ describe DiscourseAi::Automation::LlmTriage do
|
|||||||
|
|
||||||
it "can handle garbled output from LLM" do
|
it "can handle garbled output from LLM" do
|
||||||
DiscourseAi::Completions::Llm.with_prepared_responses(["Bad.\n\nYo"]) do
|
DiscourseAi::Completions::Llm.with_prepared_responses(["Bad.\n\nYo"]) do
|
||||||
triage(
|
triage(post: post, search_for_text: "bad", flag_post: true)
|
||||||
post: post,
|
|
||||||
model: "custom:#{llm_model.id}",
|
|
||||||
system_prompt: "test %%POST%%",
|
|
||||||
search_for_text: "bad",
|
|
||||||
flag_post: true,
|
|
||||||
automation: nil,
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
reviewable = ReviewablePost.last
|
reviewable = ReviewablePost.last
|
||||||
@ -111,14 +76,7 @@ describe DiscourseAi::Automation::LlmTriage do
|
|||||||
|
|
||||||
it "treats search_for_text as case-insensitive" do
|
it "treats search_for_text as case-insensitive" do
|
||||||
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
||||||
triage(
|
triage(post: post, search_for_text: "BAD", flag_post: true)
|
||||||
post: post,
|
|
||||||
model: "custom:#{llm_model.id}",
|
|
||||||
system_prompt: "test %%POST%%",
|
|
||||||
search_for_text: "BAD",
|
|
||||||
flag_post: true,
|
|
||||||
automation: nil,
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
reviewable = ReviewablePost.last
|
reviewable = ReviewablePost.last
|
||||||
|
Loading…
x
Reference in New Issue
Block a user