diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index c6bab5b4..b658787d 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -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" diff --git a/discourse_automation/llm_triage.rb b/discourse_automation/llm_triage.rb index 99e6c5f0..a290a0b3 100644 --- a/discourse_automation/llm_triage.rb +++ b/discourse_automation/llm_triage.rb @@ -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") diff --git a/lib/automation/llm_triage.rb b/lib/automation/llm_triage.rb index e4d12e51..76e4b846 100644 --- a/lib/automation/llm_triage.rb +++ b/lib/automation/llm_triage.rb @@ -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 diff --git a/spec/lib/discourse_automation/llm_triage_spec.rb b/spec/lib/discourse_automation/llm_triage_spec.rb index 34579c07..4aef5a57 100644 --- a/spec/lib/discourse_automation/llm_triage_spec.rb +++ b/spec/lib/discourse_automation/llm_triage_spec.rb @@ -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") diff --git a/spec/lib/modules/automation/llm_triage_spec.rb b/spec/lib/modules/automation/llm_triage_spec.rb index bd3830cd..69f2c706 100644 --- a/spec/lib/modules/automation/llm_triage_spec.rb +++ b/spec/lib/modules/automation/llm_triage_spec.rb @@ -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