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:
parent
e15984029d
commit
129ced9088
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,18 +86,14 @@ 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(:name)
|
.pluck(:id, :name)
|
||||||
.map { |s| { name: s, score: rand(0.0...45.0) } }
|
.map { |s| { id: s[0], name: s[1], score: rand(0.0...45.0) } }
|
||||||
.sort { |h| h[:score] }
|
.sort { |h| h[:score] }
|
||||||
DiscourseAi::AiHelper::SemanticCategorizer
|
DiscourseAi::AiHelper::SemanticCategorizer.any_instance.stubs(:categories).returns(response)
|
||||||
.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
|
||||||
|
@ -109,7 +105,6 @@ RSpec.describe "AI Post helper", type: :system, js: true do
|
||||||
expect(category_selector["data-name"]).to eq(suggestion)
|
expect(category_selector["data-name"]).to eq(suggestion)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
context "when suggesting tags with AI tag suggester" do
|
context "when suggesting tags with AI tag suggester" do
|
||||||
before do
|
before do
|
||||||
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue