mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 10:40:39 +08:00
8938ecabc2
* 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'
50 lines
990 B
Ruby
50 lines
990 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Summarization
|
|
class Base
|
|
def self.available_strategies
|
|
DiscoursePluginRegistry.summarization_strategies
|
|
end
|
|
|
|
def self.find_strategy(strategy_model)
|
|
available_strategies.detect { |s| s.model == strategy_model }
|
|
end
|
|
|
|
def self.selected_strategy
|
|
return if SiteSetting.summarization_strategy.blank?
|
|
|
|
find_strategy(SiteSetting.summarization_strategy)
|
|
end
|
|
|
|
def initialize(model)
|
|
@model = model
|
|
end
|
|
|
|
attr_reader :model
|
|
|
|
def can_request_summaries?(user)
|
|
user_group_ids = user.group_ids
|
|
|
|
SiteSetting.custom_summarization_allowed_groups_map.any? do |group_id|
|
|
user_group_ids.include?(group_id)
|
|
end
|
|
end
|
|
|
|
def correctly_configured?
|
|
raise NotImplemented
|
|
end
|
|
|
|
def display_name
|
|
raise NotImplemented
|
|
end
|
|
|
|
def configuration_hint
|
|
raise NotImplemented
|
|
end
|
|
|
|
def summarize(content)
|
|
raise NotImplemented
|
|
end
|
|
end
|
|
end
|