Revert "FEATURE: Triage rule can skip posts created via email (#775)" (#776)

This reverts commit 6af415f7f0.
This commit is contained in:
Roman Rizzi 2024-08-27 15:45:55 -03:00 committed by GitHub
parent 6af415f7f0
commit 72607c3560
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 52 additions and 51 deletions

View File

@ -99,9 +99,6 @@ 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"

View File

@ -19,7 +19,6 @@ 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
@ -43,9 +42,6 @@ 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,

View File

@ -62,38 +62,4 @@ 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

View File

@ -4,15 +4,19 @@ describe DiscourseAi::Automation::LlmTriage do
fab!(:llm_model) fab!(:llm_model)
def triage(**args) def triage(**args)
rule_args = { model: "custom:#{llm_model.id}", automation: nil, system_prompt: "test" }.merge( DiscourseAi::Automation::LlmTriage.handle(**args)
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(post: post, hide_topic: true, search_for_text: "bad") triage(
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)
@ -20,7 +24,14 @@ 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(post: post, hide_topic: true, search_for_text: "bad") triage(
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)
@ -30,7 +41,14 @@ 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(post: post, category_id: category.id, search_for_text: "bad") triage(
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)
@ -41,9 +59,12 @@ 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
@ -55,7 +76,14 @@ 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(post: post, search_for_text: "bad", flag_post: true) triage(
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
@ -66,7 +94,14 @@ 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(post: post, search_for_text: "bad", flag_post: true) triage(
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
@ -76,7 +111,14 @@ 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(post: post, search_for_text: "BAD", flag_post: true) triage(
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