Skip to content

Commit 129ced9

Browse files
authored
FIX: Split topic suggester fixes (#1253)
This update fixes a few issues in the split topic suggester. It fixes an issue where not all the category suggestions were appearing in the client. It also fixes an issue where the `move-post` request fails when creating a new topic with only one tag suggestion.
1 parent e159840 commit 129ced9

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

assets/javascripts/discourse/components/ai-split-topic-suggester.gjs

+8-4
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ export default class AiSplitTopicSuggester extends Component {
4949
if (this.args.mode === this.SUGGESTION_TYPES.title) {
5050
this.suggestions = result.suggestions;
5151
} else if (this.args.mode === this.SUGGESTION_TYPES.category) {
52-
const suggestions = result.assistant.map((s) => s.name);
53-
const suggestedCategories = this.site.categories.filter((item) =>
54-
suggestions.includes(item.name.toLowerCase())
52+
const suggestionIds = result.assistant.map((s) => s.id);
53+
const suggestedCategories = this.site.categories.filter((category) =>
54+
suggestionIds.includes(category.id)
5555
);
5656
this.suggestions = suggestedCategories;
5757
} else if (this.args.mode === this.SUGGESTION_TYPES.tag) {
@@ -95,7 +95,11 @@ export default class AiSplitTopicSuggester extends Component {
9595
this.args.updateAction([...new Set(updatedTags)]);
9696
}
9797
} else {
98-
this.args.updateAction(suggestion);
98+
if (Array.isArray(suggestion)) {
99+
this.args.updateAction([...suggestion]);
100+
} else {
101+
this.args.updateAction([suggestion]);
102+
}
99103
}
100104
return menu.close();
101105
}

spec/system/ai_helper/ai_split_topic_suggestion_spec.rb

+15-21
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,23 @@ def open_move_topic_modal
8686
SiteSetting.ai_embeddings_enabled = true
8787
end
8888

89-
skip "TODO: Category suggester only loading one category in test" do
90-
it "updates the category with the suggested category" do
91-
response =
92-
Category
93-
.take(3)
94-
.pluck(:name)
95-
.map { |s| { name: s, score: rand(0.0...45.0) } }
96-
.sort { |h| h[:score] }
97-
DiscourseAi::AiHelper::SemanticCategorizer
98-
.any_instance
99-
.stubs(:categories)
100-
.returns(response)
89+
it "updates the category with the suggested category" do
90+
response =
91+
Category
92+
.take(3)
93+
.pluck(:id, :name)
94+
.map { |s| { id: s[0], name: s[1], score: rand(0.0...45.0) } }
95+
.sort { |h| h[:score] }
96+
DiscourseAi::AiHelper::SemanticCategorizer.any_instance.stubs(:categories).returns(response)
10197

102-
open_move_topic_modal
103-
suggestion_menu.click_suggest_category_button
104-
wait_for { suggestion_menu.has_dropdown? }
105-
suggestion = category.name
106-
suggestion_menu.select_suggestion_by_name(suggestion)
107-
category_selector = page.find(".category-chooser summary")
98+
open_move_topic_modal
99+
suggestion_menu.click_suggest_category_button
100+
wait_for { suggestion_menu.has_dropdown? }
101+
suggestion = category.name
102+
suggestion_menu.select_suggestion_by_name(suggestion)
103+
category_selector = page.find(".category-chooser summary")
108104

109-
expect(category_selector["data-name"]).to eq(suggestion)
110-
end
105+
expect(category_selector["data-name"]).to eq(suggestion)
111106
end
112107
end
113108

@@ -133,7 +128,6 @@ def open_move_topic_modal
133128
suggestion = suggestion_menu.suggestion_name(0)
134129
suggestion_menu.select_suggestion_by_value(0)
135130
tag_selector = page.find(".tag-chooser summary")
136-
137131
expect(tag_selector["data-name"]).to eq(suggestion)
138132
end
139133
end

0 commit comments

Comments
 (0)