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.
This commit is contained in:
Keegan George 2025-04-09 13:12:34 -07:00 committed by GitHub
parent e15984029d
commit 129ced9088
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 25 deletions

View File

@ -49,9 +49,9 @@ export default class AiSplitTopicSuggester extends Component {
if (this.args.mode === this.SUGGESTION_TYPES.title) { if (this.args.mode === this.SUGGESTION_TYPES.title) {
this.suggestions = result.suggestions; this.suggestions = result.suggestions;
} else if (this.args.mode === this.SUGGESTION_TYPES.category) { } else if (this.args.mode === this.SUGGESTION_TYPES.category) {
const suggestions = result.assistant.map((s) => s.name); const suggestionIds = result.assistant.map((s) => s.id);
const suggestedCategories = this.site.categories.filter((item) => const suggestedCategories = this.site.categories.filter((category) =>
suggestions.includes(item.name.toLowerCase()) suggestionIds.includes(category.id)
); );
this.suggestions = suggestedCategories; this.suggestions = suggestedCategories;
} else if (this.args.mode === this.SUGGESTION_TYPES.tag) { } else if (this.args.mode === this.SUGGESTION_TYPES.tag) {
@ -95,7 +95,11 @@ export default class AiSplitTopicSuggester extends Component {
this.args.updateAction([...new Set(updatedTags)]); this.args.updateAction([...new Set(updatedTags)]);
} }
} else { } else {
this.args.updateAction(suggestion); if (Array.isArray(suggestion)) {
this.args.updateAction([...suggestion]);
} else {
this.args.updateAction([suggestion]);
}
} }
return menu.close(); return menu.close();
} }

View File

@ -86,28 +86,23 @@ RSpec.describe "AI Post helper", type: :system, js: true do
SiteSetting.ai_embeddings_enabled = true SiteSetting.ai_embeddings_enabled = true
end end
skip "TODO: Category suggester only loading one category in test" do it "updates the category with the suggested category" do
it "updates the category with the suggested category" do response =
response = Category
Category .take(3)
.take(3) .pluck(:id, :name)
.pluck(:name) .map { |s| { id: s[0], name: s[1], score: rand(0.0...45.0) } }
.map { |s| { name: s, score: rand(0.0...45.0) } } .sort { |h| h[:score] }
.sort { |h| h[:score] } DiscourseAi::AiHelper::SemanticCategorizer.any_instance.stubs(:categories).returns(response)
DiscourseAi::AiHelper::SemanticCategorizer
.any_instance
.stubs(:categories)
.returns(response)
open_move_topic_modal open_move_topic_modal
suggestion_menu.click_suggest_category_button suggestion_menu.click_suggest_category_button
wait_for { suggestion_menu.has_dropdown? } wait_for { suggestion_menu.has_dropdown? }
suggestion = category.name suggestion = category.name
suggestion_menu.select_suggestion_by_name(suggestion) suggestion_menu.select_suggestion_by_name(suggestion)
category_selector = page.find(".category-chooser summary") category_selector = page.find(".category-chooser summary")
expect(category_selector["data-name"]).to eq(suggestion) expect(category_selector["data-name"]).to eq(suggestion)
end
end end
end end
@ -133,7 +128,6 @@ RSpec.describe "AI Post helper", type: :system, js: true do
suggestion = suggestion_menu.suggestion_name(0) suggestion = suggestion_menu.suggestion_name(0)
suggestion_menu.select_suggestion_by_value(0) suggestion_menu.select_suggestion_by_value(0)
tag_selector = page.find(".tag-chooser summary") tag_selector = page.find(".tag-chooser summary")
expect(tag_selector["data-name"]).to eq(suggestion) expect(tag_selector["data-name"]).to eq(suggestion)
end end
end end