FIX: Avoid replying to the reply user for llm_triage automation (#544)
Avoid replying to the reply user. This causes an infinite conversation from the reply_user to the reply_user
This commit is contained in:
parent
1d476e3b68
commit
f3b3312ce0
|
@ -34,8 +34,15 @@ if defined?(DiscourseAutomation)
|
|||
field :canned_reply, component: :message
|
||||
field :canned_reply_user, component: :user
|
||||
|
||||
script do |context, fields, automation|
|
||||
script do |context, fields|
|
||||
post = context["post"]
|
||||
canned_reply = fields.dig("canned_reply", "value")
|
||||
canned_reply_user = fields.dig("canned_reply_user", "value")
|
||||
|
||||
# nothing to do if we already replied
|
||||
next if post.user.username == canned_reply_user
|
||||
next if post.raw.strip == canned_reply.to_s.strip
|
||||
|
||||
system_prompt = fields["system_prompt"]["value"]
|
||||
search_for_text = fields["search_for_text"]["value"]
|
||||
model = fields["model"]["value"]
|
||||
|
@ -49,13 +56,6 @@ if defined?(DiscourseAutomation)
|
|||
tags = fields.dig("tags", "value")
|
||||
hide_topic = fields.dig("hide_topic", "value")
|
||||
flag_post = fields.dig("flag_post", "value")
|
||||
canned_reply = fields.dig("canned_reply", "value")
|
||||
canned_reply_user = fields.dig("canned_reply_user", "value")
|
||||
|
||||
if post.raw.strip == canned_reply.to_s.strip
|
||||
# nothing to do if we already replied
|
||||
next
|
||||
end
|
||||
|
||||
begin
|
||||
DiscourseAi::Automation::LlmTriage.handle(
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
return if !defined?(DiscourseAutomation)
|
||||
|
||||
describe DiscourseAi::Automation::LlmTriage do
|
||||
fab!(:post)
|
||||
fab!(:category)
|
||||
fab!(:reply_user) { Fabricate(:user) }
|
||||
|
||||
let(:automation) { Fabricate(:automation, script: "llm_triage", enabled: true) }
|
||||
|
||||
|
@ -18,12 +19,8 @@ describe DiscourseAi::Automation::LlmTriage do
|
|||
)
|
||||
end
|
||||
|
||||
it "can trigger via automation" do
|
||||
before do
|
||||
SiteSetting.tagging_enabled = true
|
||||
|
||||
category = Fabricate(:category)
|
||||
user = Fabricate(:user)
|
||||
|
||||
add_automation_field("system_prompt", "hello %%POST%%")
|
||||
add_automation_field("search_for_text", "bad")
|
||||
add_automation_field("model", "gpt-4")
|
||||
|
@ -32,7 +29,11 @@ describe DiscourseAi::Automation::LlmTriage do
|
|||
add_automation_field("hide_topic", 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_user", user.username, type: "user")
|
||||
add_automation_field("canned_reply_user", reply_user.username, type: "user")
|
||||
end
|
||||
|
||||
it "can trigger via automation" do
|
||||
post = Fabricate(:post)
|
||||
|
||||
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
||||
automation.running_in_background!
|
||||
|
@ -45,6 +46,18 @@ describe DiscourseAi::Automation::LlmTriage do
|
|||
expect(topic.visible).to eq(false)
|
||||
reply = topic.posts.order(:post_number).last
|
||||
expect(reply.raw).to eq("Yo this is a reply")
|
||||
expect(reply.user.id).to eq(user.id)
|
||||
expect(reply.user.id).to eq(reply_user.id)
|
||||
end
|
||||
|
||||
it "does not reply to the canned_reply_user" do
|
||||
post = Fabricate(:post, user: reply_user)
|
||||
|
||||
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 post.raw
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue