FIX: Triage rule should append selected tags instead of replacing them (#1022)

This commit is contained in:
Roman Rizzi 2024-12-11 11:19:44 -03:00 committed by GitHub
parent 34f43f398d
commit 5fc7a730ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View File

@ -66,7 +66,9 @@ module DiscourseAi
changes = {}
changes[:category_id] = category_id if category_id.present?
changes[:tags] = tags if SiteSetting.tagging_enabled? && tags.present?
if SiteSetting.tagging_enabled? && tags.present?
changes[:tags] = post.topic.tags.map(&:name).concat(tags)
end
if changes.present?
first_post = post.topic.posts.where(post_number: 1).first

View File

@ -198,4 +198,24 @@ describe DiscourseAi::Automation::LlmTriage do
expect(spy.model_params[:stop_sequences]).to contain_exactly(*sequences)
end
end
it "append rule tags instead of replacing them" do
tag_1 = Fabricate(:tag)
tag_2 = Fabricate(:tag)
post.topic.update!(tags: [tag_1])
DiscourseAi::Completions::Llm.with_prepared_responses(["bad"]) do
triage(
post: post,
model: "custom:#{llm_model.id}",
system_prompt: "test %%POST%%",
search_for_text: "bad",
flag_post: true,
tags: [tag_2.name],
automation: nil,
)
end
expect(post.topic.reload.tags).to contain_exactly(tag_1, tag_2)
end
end