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!
|
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
|
status: 200
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -81,7 +85,9 @@ module DiscourseAi
|
||||||
|
|
||||||
RateLimiter.new(current_user, "ai_assistant", 6, 3.minutes).performed!
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -2,7 +2,8 @@
|
||||||
module DiscourseAi
|
module DiscourseAi
|
||||||
module AiHelper
|
module AiHelper
|
||||||
class SemanticCategorizer
|
class SemanticCategorizer
|
||||||
def initialize(text)
|
def initialize(text, user)
|
||||||
|
@user = user
|
||||||
@text = text
|
@text = text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -22,6 +23,7 @@ module DiscourseAi
|
||||||
::Topic
|
::Topic
|
||||||
.joins(:category)
|
.joins(:category)
|
||||||
.where(id: candidate_ids)
|
.where(id: candidate_ids)
|
||||||
|
.where("categories.id IN (?)", Category.topic_create_allowed(@user.guardian).pluck(:id))
|
||||||
.order("array_position(ARRAY#{candidate_ids}, topics.id)")
|
.order("array_position(ARRAY#{candidate_ids}, topics.id)")
|
||||||
.pluck("categories.slug")
|
.pluck("categories.slug")
|
||||||
.map
|
.map
|
||||||
|
@ -52,6 +54,7 @@ module DiscourseAi
|
||||||
::Topic
|
::Topic
|
||||||
.joins(:topic_tags, :tags)
|
.joins(:topic_tags, :tags)
|
||||||
.where(id: candidate_ids)
|
.where(id: candidate_ids)
|
||||||
|
.where("tags.id IN (?)", DiscourseTagging.visible_tags(@user.guardian).pluck(:id))
|
||||||
.group("topics.id")
|
.group("topics.id")
|
||||||
.order("array_position(ARRAY#{candidate_ids}, topics.id)")
|
.order("array_position(ARRAY#{candidate_ids}, topics.id)")
|
||||||
.pluck("array_agg(tags.name)")
|
.pluck("array_agg(tags.name)")
|
||||||
|
|
Loading…
Reference in New Issue