Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ export default class AiTagSuggester extends Component {
}

#tagSelectorHasValues() {
return this.args.composer?.tags && this.args.composer?.tags.length > 0;
const model = this.args.composer ? this.args.composer : this.args.buffered;

return model.get("tags") && model.get("tags").length > 0;
}

#removedAppliedTag(suggestion) {
Expand Down
2 changes: 1 addition & 1 deletion lib/ai_helper/semantic_categorizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def tags
.group_by { |c| c[:name] }
.map { |name, scores| { name: name, score: scores.sum { |s| s[:score] } } }
.sort_by { |c| -c[:score] }
.take(5)
.take(7)
.then do |tags|
models = Tag.where(name: tags.map { _1[:name] }).index_by(&:name)
tags.map do |tag|
Expand Down
34 changes: 33 additions & 1 deletion spec/system/ai_helper/ai_composer_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
let(:diff_modal) { PageObjects::Modals::DiffModal.new }
let(:ai_suggestion_dropdown) { PageObjects::Components::AiSuggestionDropdown.new }
let(:toasts) { PageObjects::Components::Toasts.new }
let(:topic_page) { PageObjects::Pages::Topic.new }

fab!(:category)
fab!(:category_2) { Fabricate(:category) }
Expand All @@ -25,6 +26,18 @@
fab!(:cloud) { Fabricate(:tag) }
fab!(:feedback) { Fabricate(:tag) }
fab!(:review) { Fabricate(:tag) }
fab!(:topic) { Fabricate(:topic, category: category, tags: [video, music]) }
fab!(:post) do
Fabricate(
:post,
topic: topic,
raw:
"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.",
)
end
fab!(:post_2) do
Fabricate(:post, topic: topic, raw: "La lluvia en España se queda principalmente en el avión.")
end

def trigger_composer_helper(content)
visit("/latest")
Expand Down Expand Up @@ -266,7 +279,7 @@ def trigger_composer_helper(content)
it "updates the tag with the suggested tag" do
response =
Tag
.take(5)
.take(7)
.pluck(:name)
.map { |s| { name: s, score: rand(0.0...45.0) } }
.sort { |h| h[:score] }
Expand All @@ -286,6 +299,25 @@ def trigger_composer_helper(content)

expect(tag_selector["data-name"]).to eq(suggestion)
end

it "does not suggest tags that already exist" do
response =
Tag
.take(7)
.pluck(:name)
.map { |s| { name: s, score: rand(0.0...45.0) } }
.sort { |h| h[:score] }
DiscourseAi::AiHelper::SemanticCategorizer.any_instance.stubs(:tags).returns(response)

topic_page.visit_topic(topic)
page.find(".edit-topic").click
page.find(".ai-tag-suggester-trigger").click
tag1_css = ".ai-tag-suggester-content btn[data-name='#{video.name}']"
tag2_css = ".ai-tag-suggester-content btn[data-name='#{music.name}']"

expect(page).to have_no_css(tag1_css)
expect(page).to have_no_css(tag2_css)
end
end

context "when AI helper is disabled" do
Expand Down
Loading