FEATURE: Return only applicable suggestions in AiHelper category/tags suggestions (#184)
This commit is contained in:
parent
3c4a53b2cb
commit
4864978495
|
@ -72,7 +72,11 @@ module DiscourseAi
|
|||
|
||||
RateLimiter.new(current_user, "ai_assistant", 6, 3.minutes).performed!
|
||||
|
||||
render json: DiscourseAi::AiHelper::SemanticCategorizer.new(params[:text]).categories,
|
||||
render json:
|
||||
DiscourseAi::AiHelper::SemanticCategorizer.new(
|
||||
params[:text],
|
||||
current_user,
|
||||
).categories,
|
||||
status: 200
|
||||
end
|
||||
|
||||
|
@ -81,7 +85,9 @@ module DiscourseAi
|
|||
|
||||
RateLimiter.new(current_user, "ai_assistant", 6, 3.minutes).performed!
|
||||
|
||||
render json: DiscourseAi::AiHelper::SemanticCategorizer.new(params[:text]).tags, status: 200
|
||||
render json:
|
||||
DiscourseAi::AiHelper::SemanticCategorizer.new(params[:text], current_user).tags,
|
||||
status: 200
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
module DiscourseAi
|
||||
module AiHelper
|
||||
class SemanticCategorizer
|
||||
def initialize(text)
|
||||
def initialize(text, user)
|
||||
@user = user
|
||||
@text = text
|
||||
end
|
||||
|
||||
|
@ -22,6 +23,7 @@ module DiscourseAi
|
|||
::Topic
|
||||
.joins(:category)
|
||||
.where(id: candidate_ids)
|
||||
.where("categories.id IN (?)", Category.topic_create_allowed(@user.guardian).pluck(:id))
|
||||
.order("array_position(ARRAY#{candidate_ids}, topics.id)")
|
||||
.pluck("categories.slug")
|
||||
.map
|
||||
|
@ -52,6 +54,7 @@ module DiscourseAi
|
|||
::Topic
|
||||
.joins(:topic_tags, :tags)
|
||||
.where(id: candidate_ids)
|
||||
.where("tags.id IN (?)", DiscourseTagging.visible_tags(@user.guardian).pluck(:id))
|
||||
.group("topics.id")
|
||||
.order("array_position(ARRAY#{candidate_ids}, topics.id)")
|
||||
.pluck("array_agg(tags.name)")
|
||||
|
|
Loading…
Reference in New Issue