2023-12-18 20:04:15 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
describe DiscourseAi::Automation::LlmTriage do
|
|
|
|
fab!(:post) { Fabricate(:post) }
|
|
|
|
|
|
|
|
def triage(**args)
|
|
|
|
DiscourseAi::Automation::LlmTriage.handle(**args)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does nothing if it does not pass triage" do
|
|
|
|
DiscourseAi::Completions::Llm.with_prepared_responses(["good"]) do
|
|
|
|
triage(
|
|
|
|
post: post,
|
2024-01-29 14:04:25 -05:00
|
|
|
model: "fake:fake",
|
2023-12-18 20:04:15 -05:00
|
|
|
hide_topic: true,
|
|
|
|
system_prompt: "test %%POST%%",
|
|
|
|
search_for_text: "bad",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(post.topic.reload.visible).to eq(true)
|
|
|
|
end
|
|
|
|
|
2024-01-29 14:04:25 -05:00
|
|
|
it "can hide topics on triage" do
|
2023-12-18 20:04:15 -05:00
|
|
|
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
|
|
|
triage(
|
|
|
|
post: post,
|
2024-01-29 14:04:25 -05:00
|
|
|
model: "fake:fake",
|
2023-12-18 20:04:15 -05:00
|
|
|
hide_topic: true,
|
|
|
|
system_prompt: "test %%POST%%",
|
|
|
|
search_for_text: "bad",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(post.topic.reload.visible).to eq(false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can categorize topics on triage" do
|
|
|
|
category = Fabricate(:category)
|
|
|
|
|
|
|
|
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
|
|
|
triage(
|
|
|
|
post: post,
|
2024-01-29 14:04:25 -05:00
|
|
|
model: "fake:fake",
|
2023-12-18 20:04:15 -05:00
|
|
|
category_id: category.id,
|
|
|
|
system_prompt: "test %%POST%%",
|
|
|
|
search_for_text: "bad",
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(post.topic.reload.category_id).to eq(category.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "can reply to topics on triage" do
|
|
|
|
user = Fabricate(:user)
|
|
|
|
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
|
|
|
|
triage(
|
|
|
|
post: post,
|
2024-01-29 14:04:25 -05:00
|
|
|
model: "fake:fake",
|
2023-12-18 20:04:15 -05:00
|
|
|
system_prompt: "test %%POST%%",
|
|
|
|
search_for_text: "bad",
|
|
|
|
canned_reply: "test canned reply 123",
|
|
|
|
canned_reply_user: user.username,
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
reply = post.topic.posts.order(:post_number).last
|
|
|
|
|
|
|
|
expect(reply.raw).to eq("test canned reply 123")
|
|
|
|
expect(reply.user.id).to eq(user.id)
|
|
|
|
end
|
|
|
|
end
|