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:
parent
6a30b06a55
commit
1b72a00d2c
|
@ -96,6 +96,9 @@ en:
|
|||
hide_topic:
|
||||
label: "Hide topic"
|
||||
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:
|
||||
label: "Model"
|
||||
description: "Either gpt-4 or gpt-3-5-turbo or claude-2"
|
||||
|
|
|
@ -32,6 +32,7 @@ if defined?(DiscourseAutomation)
|
|||
field :category, component: :category
|
||||
field :tags, component: :tags
|
||||
field :hide_topic, component: :boolean
|
||||
field :flag_post, component: :boolean
|
||||
field :canned_reply, component: :message
|
||||
field :canned_reply_user, component: :user
|
||||
|
||||
|
@ -49,6 +50,7 @@ if defined?(DiscourseAutomation)
|
|||
category_id = fields.dig("category", "value")
|
||||
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")
|
||||
|
||||
|
@ -68,6 +70,7 @@ if defined?(DiscourseAutomation)
|
|||
canned_reply: canned_reply,
|
||||
canned_reply_user: canned_reply_user,
|
||||
hide_topic: hide_topic,
|
||||
flag_post: flag_post,
|
||||
)
|
||||
rescue => e
|
||||
Discourse.warn_exception(e, message: "llm_triage: failed to run inference")
|
||||
|
|
|
@ -12,9 +12,11 @@ module DiscourseAi
|
|||
tags: nil,
|
||||
canned_reply: 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!"
|
||||
end
|
||||
|
||||
|
@ -65,6 +67,8 @@ module DiscourseAi
|
|||
end
|
||||
|
||||
post.topic.update!(visible: false) if hide_topic
|
||||
|
||||
ReviewablePost.needs_review!(target: post, created_by: Discourse.system_user) if flag_post
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ describe DiscourseAi::Automation::LlmTriage do
|
|||
add_automation_field("category", category.id, type: "category")
|
||||
add_automation_field("tags", %w[aaa bbb], type: "tags")
|
||||
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")
|
||||
|
||||
|
|
|
@ -68,4 +68,20 @@ describe DiscourseAi::Automation::LlmTriage do
|
|||
expect(reply.raw).to eq("test canned reply 123")
|
||||
expect(reply.user.id).to eq(user.id)
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue