2023-04-04 10:24:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module DiscourseAi
|
|
|
|
module Summarization
|
2024-07-03 20:48:18 -04:00
|
|
|
def self.default_strategy
|
|
|
|
if SiteSetting.ai_summarization_model.present? && SiteSetting.ai_summarization_enabled
|
|
|
|
DiscourseAi::Summarization::Strategies::FoldContent.new(SiteSetting.ai_summarization_model)
|
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-04-04 10:24:09 -04:00
|
|
|
class EntryPoint
|
|
|
|
def inject_into(plugin)
|
2024-07-02 11:51:59 -04:00
|
|
|
plugin.add_to_serializer(:current_user, :can_summarize) do
|
2024-07-03 20:48:18 -04:00
|
|
|
return false if !SiteSetting.ai_summarization_enabled
|
2024-07-02 11:51:59 -04:00
|
|
|
scope.user.in_any_groups?(SiteSetting.ai_custom_summarization_allowed_groups_map)
|
2024-01-29 14:04:25 -05:00
|
|
|
end
|
|
|
|
|
2024-07-02 11:51:59 -04:00
|
|
|
plugin.add_to_serializer(:topic_view, :summarizable) do
|
2024-07-03 20:48:18 -04:00
|
|
|
scope.can_see_summary?(object.topic)
|
2024-01-29 14:04:25 -05:00
|
|
|
end
|
|
|
|
|
2024-07-02 11:51:59 -04:00
|
|
|
plugin.add_to_serializer(:web_hook_topic_view, :summarizable) do
|
2024-07-03 20:48:18 -04:00
|
|
|
scope.can_see_summary?(object.topic)
|
2023-06-27 11:26:33 -04:00
|
|
|
end
|
2023-04-04 10:24:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|