mirror of
https://github.com/discourse/discourse.git
synced 2025-05-31 06:49:30 +08:00
FEATURE: Custom content summarization strategies. (#21813)
* FEATURE: Content custom summarization strategies. This PR establishes a pattern for plugins to register alternative ways of summarizing content by extending a class that defines an interface. Core controls which strategy we'll use and who has access to it through the `summarization_strategy` and `custom_summarization_allowed_groups`. It also defines the UI for summarizing topics. Other plugins can access this summarization mechanism and implement their features, removing cross-plugin customizations, as it currently happens between chat and the discourse-ai plugin. * Group membership validation and rate limiting * Work with objects instead of classes * Port summarization feature from discourse-ai to chat * Rename available summaries to 'Top Replies' and 'Summary'
This commit is contained in:
@ -30,6 +30,7 @@ class TopicsController < ApplicationController
|
||||
publish
|
||||
reset_bump_date
|
||||
set_slow_mode
|
||||
summary
|
||||
]
|
||||
|
||||
before_action :consider_user_for_promotion, only: :show
|
||||
@ -1167,6 +1168,30 @@ class TopicsController < ApplicationController
|
||||
head :ok
|
||||
end
|
||||
|
||||
def summary
|
||||
topic = Topic.find(params[:topic_id])
|
||||
guardian.ensure_can_see!(topic)
|
||||
strategy = Summarization::Base.selected_strategy
|
||||
raise Discourse::NotFound.new unless strategy
|
||||
|
||||
raise Discourse::InvalidAccess unless strategy.can_request_summaries?(current_user)
|
||||
|
||||
RateLimiter.new(current_user, "summary", 6, 5.minutes).performed!
|
||||
|
||||
hijack do
|
||||
summary_opts = {
|
||||
filter: "summary",
|
||||
exclude_deleted_users: true,
|
||||
exclude_hidden: true,
|
||||
show_deleted: false,
|
||||
}
|
||||
|
||||
content = TopicView.new(topic, current_user, summary_opts).posts.pluck(:raw).join("\n")
|
||||
|
||||
render json: { summary: strategy.summarize(content) }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def topic_params
|
||||
|
Reference in New Issue
Block a user