diff --git a/lib/automation/llm_triage.rb b/lib/automation/llm_triage.rb index d8bffa73..937696de 100644 --- a/lib/automation/llm_triage.rb +++ b/lib/automation/llm_triage.rb @@ -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 diff --git a/spec/lib/modules/automation/llm_triage_spec.rb b/spec/lib/modules/automation/llm_triage_spec.rb index 7e434603..c45c0f13 100644 --- a/spec/lib/modules/automation/llm_triage_spec.rb +++ b/spec/lib/modules/automation/llm_triage_spec.rb @@ -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