FEATURE: Option for AI triage to send a post to the review queue (#498)

Option for AI triage to send a post to the review queue
This commit is contained in:
Rafael dos Santos Silva 2024-02-28 22:33:28 -03:00 committed by GitHub
parent 6a30b06a55
commit 1b72a00d2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 2 deletions

View File

@ -96,6 +96,9 @@ en:
hide_topic: hide_topic:
label: "Hide topic" label: "Hide topic"
description: "Make topic non visible to the public if triggered" description: "Make topic non visible to the public if triggered"
flag_post:
label: "Send to review"
description: "Puts the post into the review queue if triggered, for moderators to triage"
model: model:
label: "Model" label: "Model"
description: "Either gpt-4 or gpt-3-5-turbo or claude-2" description: "Either gpt-4 or gpt-3-5-turbo or claude-2"

View File

@ -32,6 +32,7 @@ if defined?(DiscourseAutomation)
field :category, component: :category field :category, component: :category
field :tags, component: :tags field :tags, component: :tags
field :hide_topic, component: :boolean field :hide_topic, component: :boolean
field :flag_post, component: :boolean
field :canned_reply, component: :message field :canned_reply, component: :message
field :canned_reply_user, component: :user field :canned_reply_user, component: :user
@ -49,6 +50,7 @@ if defined?(DiscourseAutomation)
category_id = fields.dig("category", "value") category_id = fields.dig("category", "value")
tags = fields.dig("tags", "value") tags = fields.dig("tags", "value")
hide_topic = fields.dig("hide_topic", "value") hide_topic = fields.dig("hide_topic", "value")
flag_post = fields.dig("flag_post", "value")
canned_reply = fields.dig("canned_reply", "value") canned_reply = fields.dig("canned_reply", "value")
canned_reply_user = fields.dig("canned_reply_user", "value") canned_reply_user = fields.dig("canned_reply_user", "value")
@ -68,6 +70,7 @@ if defined?(DiscourseAutomation)
canned_reply: canned_reply, canned_reply: canned_reply,
canned_reply_user: canned_reply_user, canned_reply_user: canned_reply_user,
hide_topic: hide_topic, hide_topic: hide_topic,
flag_post: flag_post,
) )
rescue => e rescue => e
Discourse.warn_exception(e, message: "llm_triage: failed to run inference") Discourse.warn_exception(e, message: "llm_triage: failed to run inference")

View File

@ -12,9 +12,11 @@ module DiscourseAi
tags: nil, tags: nil,
canned_reply: nil, canned_reply: nil,
canned_reply_user: nil, canned_reply_user: nil,
hide_topic: nil hide_topic: nil,
flag_post: nil
) )
if category_id.blank? && tags.blank? && canned_reply.blank? && hide_topic.blank? if category_id.blank? && tags.blank? && canned_reply.blank? && hide_topic.blank? &&
flag_post.blank?
raise ArgumentError, "llm_triage: no action specified!" raise ArgumentError, "llm_triage: no action specified!"
end end
@ -65,6 +67,8 @@ module DiscourseAi
end end
post.topic.update!(visible: false) if hide_topic post.topic.update!(visible: false) if hide_topic
ReviewablePost.needs_review!(target: post, created_by: Discourse.system_user) if flag_post
end end
end end

View File

@ -30,6 +30,7 @@ describe DiscourseAi::Automation::LlmTriage do
add_automation_field("category", category.id, type: "category") add_automation_field("category", category.id, type: "category")
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("canned_reply", "Yo this is a reply") 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", user.username, type: "user")

View File

@ -68,4 +68,20 @@ describe DiscourseAi::Automation::LlmTriage do
expect(reply.raw).to eq("test canned reply 123") expect(reply.raw).to eq("test canned reply 123")
expect(reply.user.id).to eq(user.id) expect(reply.user.id).to eq(user.id)
end end
it "can add posts to the review queue" do
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
triage(
post: post,
model: "gpt-4",
system_prompt: "test %%POST%%",
search_for_text: "bad",
flag_post: true,
)
end
reviewable = ReviewablePost.last
expect(reviewable.target).to eq(post)
end
end end