Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit fc88bb0

Browse files
authored
FIX: Tag suggester is suggesting already assigned tags (#990)
This PR fixes an issue where the tag suggester for edit title topic area was suggesting tags that are already assigned on a post. It also updates the amount of suggested tags to 7 so that there is still a decent amount of tags suggested when tags are already assigned.
1 parent 117c062 commit fc88bb0

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

assets/javascripts/discourse/components/suggestion-menus/ai-tag-suggester.gjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ export default class AiTagSuggester extends Component {
112112
}
113113

114114
#tagSelectorHasValues() {
115-
return this.args.composer?.tags && this.args.composer?.tags.length > 0;
115+
const model = this.args.composer ? this.args.composer : this.args.buffered;
116+
117+
return model.get("tags") && model.get("tags").length > 0;
116118
}
117119

118120
#removedAppliedTag(suggestion) {

lib/ai_helper/semantic_categorizer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def tags
7878
.group_by { |c| c[:name] }
7979
.map { |name, scores| { name: name, score: scores.sum { |s| s[:score] } } }
8080
.sort_by { |c| -c[:score] }
81-
.take(5)
81+
.take(7)
8282
.then do |tags|
8383
models = Tag.where(name: tags.map { _1[:name] }).index_by(&:name)
8484
tags.map do |tag|

spec/system/ai_helper/ai_composer_helper_spec.rb

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
let(:diff_modal) { PageObjects::Modals::DiffModal.new }
1818
let(:ai_suggestion_dropdown) { PageObjects::Components::AiSuggestionDropdown.new }
1919
let(:toasts) { PageObjects::Components::Toasts.new }
20+
let(:topic_page) { PageObjects::Pages::Topic.new }
2021

2122
fab!(:category)
2223
fab!(:category_2) { Fabricate(:category) }
@@ -25,6 +26,18 @@
2526
fab!(:cloud) { Fabricate(:tag) }
2627
fab!(:feedback) { Fabricate(:tag) }
2728
fab!(:review) { Fabricate(:tag) }
29+
fab!(:topic) { Fabricate(:topic, category: category, tags: [video, music]) }
30+
fab!(:post) do
31+
Fabricate(
32+
:post,
33+
topic: topic,
34+
raw:
35+
"I like to eat pie. It is a very good dessert. Some people are wasteful by throwing pie at others but I do not do that. I always eat the pie.",
36+
)
37+
end
38+
fab!(:post_2) do
39+
Fabricate(:post, topic: topic, raw: "La lluvia en España se queda principalmente en el avión.")
40+
end
2841

2942
def trigger_composer_helper(content)
3043
visit("/latest")
@@ -266,7 +279,7 @@ def trigger_composer_helper(content)
266279
it "updates the tag with the suggested tag" do
267280
response =
268281
Tag
269-
.take(5)
282+
.take(7)
270283
.pluck(:name)
271284
.map { |s| { name: s, score: rand(0.0...45.0) } }
272285
.sort { |h| h[:score] }
@@ -286,6 +299,25 @@ def trigger_composer_helper(content)
286299

287300
expect(tag_selector["data-name"]).to eq(suggestion)
288301
end
302+
303+
it "does not suggest tags that already exist" do
304+
response =
305+
Tag
306+
.take(7)
307+
.pluck(:name)
308+
.map { |s| { name: s, score: rand(0.0...45.0) } }
309+
.sort { |h| h[:score] }
310+
DiscourseAi::AiHelper::SemanticCategorizer.any_instance.stubs(:tags).returns(response)
311+
312+
topic_page.visit_topic(topic)
313+
page.find(".edit-topic").click
314+
page.find(".ai-tag-suggester-trigger").click
315+
tag1_css = ".ai-tag-suggester-content btn[data-name='#{video.name}']"
316+
tag2_css = ".ai-tag-suggester-content btn[data-name='#{music.name}']"
317+
318+
expect(page).to have_no_css(tag1_css)
319+
expect(page).to have_no_css(tag2_css)
320+
end
289321
end
290322

291323
context "when AI helper is disabled" do

0 commit comments

Comments
 (0)