From 3364fec425048e6dcfff50702350544fa8709df2 Mon Sep 17 00:00:00 2001 From: Roman Rizzi Date: Tue, 13 Jun 2023 14:32:26 -0300 Subject: [PATCH] DEV: Remove the summarization feature (#83) * DEV: Remove the summarization feature Instead, we'll register summarization implementations for OpenAI, Anthropic, and Discourse AI using the API defined in discourse/discourse#21813. Core and chat will implement features on top of these implementations instead of this plugin extending them. * Register instances that contain the model, requiring less site settings --- .../summarization/summary_controller.rb | 48 ------- .../discourse/components/ai-summary.hbs | 32 ----- .../discourse/components/ai-summary.js | 83 ----------- .../discourse/templates/modal/ai-summary.hbs | 6 - .../javascripts/initializers/chat-summary.js | 43 ------ .../javascripts/initializers/topic-summary.js | 48 ------- .../summarization/common/summarization.scss | 10 -- .../summarization/desktop/summarization.scss | 3 - .../summarization/mobile/summarization.scss | 9 -- config/locales/client.en.yml | 8 -- config/locales/server.en.yml | 8 +- config/routes.rb | 4 - config/settings.yml | 16 --- lib/modules/summarization/entry_point.rb | 13 +- .../summarization/strategies/anthropic.rb | 57 ++++++++ .../summarization/strategies/discourse_ai.rb | 52 +++++++ .../summarization/strategies/open_ai.rb | 51 +++++++ .../summarization/summary_generator.rb | 131 ------------------ plugin.rb | 4 - .../strategies/anthropic_spec.rb | 26 ++++ .../strategies/discourse_spec.rb | 25 ++++ .../summarization/strategies/open_ai_spec.rb | 21 +++ .../summarization/summary_controller_spec.rb | 72 ---------- spec/support/summarization_stubs.rb | 56 -------- .../page_objects/modals/summarization.rb | 24 ---- .../chat_channel_summarization_spec.rb | 36 ----- .../summarization/topic_summarization_spec.rb | 33 ----- 27 files changed, 249 insertions(+), 670 deletions(-) delete mode 100644 app/controllers/discourse_ai/summarization/summary_controller.rb delete mode 100644 assets/javascripts/discourse/components/ai-summary.hbs delete mode 100644 assets/javascripts/discourse/components/ai-summary.js delete mode 100644 assets/javascripts/discourse/templates/modal/ai-summary.hbs delete mode 100644 assets/javascripts/initializers/chat-summary.js delete mode 100644 assets/javascripts/initializers/topic-summary.js delete mode 100644 assets/stylesheets/modules/summarization/common/summarization.scss delete mode 100644 assets/stylesheets/modules/summarization/desktop/summarization.scss delete mode 100644 assets/stylesheets/modules/summarization/mobile/summarization.scss create mode 100644 lib/modules/summarization/strategies/anthropic.rb create mode 100644 lib/modules/summarization/strategies/discourse_ai.rb create mode 100644 lib/modules/summarization/strategies/open_ai.rb delete mode 100644 lib/modules/summarization/summary_generator.rb create mode 100644 spec/lib/modules/summarization/strategies/anthropic_spec.rb create mode 100644 spec/lib/modules/summarization/strategies/discourse_spec.rb create mode 100644 spec/lib/modules/summarization/strategies/open_ai_spec.rb delete mode 100644 spec/requests/summarization/summary_controller_spec.rb delete mode 100644 spec/support/summarization_stubs.rb delete mode 100644 spec/system/page_objects/modals/summarization.rb delete mode 100644 spec/system/summarization/chat_channel_summarization_spec.rb delete mode 100644 spec/system/summarization/topic_summarization_spec.rb diff --git a/app/controllers/discourse_ai/summarization/summary_controller.rb b/app/controllers/discourse_ai/summarization/summary_controller.rb deleted file mode 100644 index 11677f62..00000000 --- a/app/controllers/discourse_ai/summarization/summary_controller.rb +++ /dev/null @@ -1,48 +0,0 @@ -# frozen_string_literal: true - -module DiscourseAi - module Summarization - class SummaryController < ::ApplicationController - requires_plugin ::DiscourseAi::PLUGIN_NAME - requires_login - - VALID_SINCE_VALUES = [1, 3, 6, 12, 24, 72, 168] - VALID_TARGETS = %w[chat_channel topic] - - def show - raise PluginDisabled unless SiteSetting.ai_summarization_enabled - target_type = params[:target_type] - - raise Discourse::InvalidParameters.new(:target_type) if !VALID_TARGETS.include?(target_type) - - since = nil - - if target_type == "chat_channel" - since = params[:since].to_i - raise Discourse::InvalidParameters.new(:since) if !VALID_SINCE_VALUES.include?(since) - target = Chat::Channel.find_by(id: params[:target_id]) - raise Discourse::NotFound.new(:chat_channel) if !target - raise Discourse::InvalidAccess if !guardian.can_join_chat_channel?(target) - else - target = Topic.find_by(id: params[:target_id]) - raise Discourse::NotFound.new(:topic) if !target - raise Discourse::InvalidAccess if !guardian.can_see_topic?(target) - end - - RateLimiter.new( - current_user, - "ai_summarization", - 6, - SiteSetting.ai_summarization_rate_limit_minutes.minutes, - ).performed! - - hijack do - summary = - DiscourseAi::Summarization::SummaryGenerator.new(target, current_user).summarize!(since) - - render json: { summary: summary }, status: 200 - end - end - end - end -end diff --git a/assets/javascripts/discourse/components/ai-summary.hbs b/assets/javascripts/discourse/components/ai-summary.hbs deleted file mode 100644 index d6902b01..00000000 --- a/assets/javascripts/discourse/components/ai-summary.hbs +++ /dev/null @@ -1,32 +0,0 @@ - - {{#if @allowTimeframe}} - {{i18n "discourse_ai.summarization.description"}} - - {{/if}} - -
- - - {{#unless this.loading}} -