FEATURE: Inline topic summary. Cached version accessible to everyone. (#22551)

* FEATURE:  Inline topic summary. Cached version accessible to everyone.

Anons and non-members of the `custom_summarization_allowed_groups_map` groups can see cached summaries for any accessible topic. After the first 12 hours and if the posts to summarize have changed, allowed users clicking on the button will automatically re-generate it.

* Ensure chat summaries work and prevent model hallucinations when there are no messages.
This commit is contained in:
Roman Rizzi
2023-07-12 11:21:51 -03:00
committed by GitHub
parent 0b8fcb7c72
commit 61aeb2da90
27 changed files with 378 additions and 156 deletions

View File

@ -30,7 +30,6 @@ class TopicsController < ApplicationController
publish
reset_bump_date
set_slow_mode
summary
]
before_action :consider_user_for_promotion, only: :show
@ -1172,13 +1171,17 @@ class TopicsController < ApplicationController
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)
if strategy.nil? || !Summarization::Base.can_see_summary?(topic, current_user)
raise Discourse::NotFound
end
RateLimiter.new(current_user, "summary", 6, 5.minutes).performed!
RateLimiter.new(current_user, "summary", 6, 5.minutes).performed! if current_user
hijack { render json: { summary: TopicSummarization.new(strategy).summarize(topic) } }
hijack do
summary = TopicSummarization.new(strategy).summarize(topic, current_user)
render json: { summary: summary&.summarized_text, summarized_on: summary&.updated_at }
end
end
private