FEATURE: Stream topic summaries. (#23065)

When we receive the stream parameter, we'll queue a job that periodically publishes partial updates, and after the summarization finishes, a final one with the completed version, plus metadata.

`summary-box` listens to these updates via MessageBus, and updates state accordingly.
This commit is contained in:
Roman Rizzi
2023-08-11 15:08:49 -03:00
committed by GitHub
parent 840bea3c51
commit 7ca5ee6cd2
13 changed files with 370 additions and 127 deletions

View File

@ -1185,18 +1185,21 @@ class TopicsController < ApplicationController
opts = params.permit(:skip_age_check)
hijack do
summary = TopicSummarization.new(strategy).summarize(topic, current_user, opts)
if params[:stream]
Jobs.enqueue(
:stream_topic_summary,
topic_id: topic.id,
user_id: current_user.id,
opts: opts.as_json,
)
render json: {
summary: summary.summarized_text,
summarized_on: summary.updated_at,
summarized_by: summary.algorithm,
outdated: summary.outdated,
can_regenerate: Summarization::Base.can_request_summary_for?(current_user),
new_posts_since_summary:
topic.highest_post_number.to_i - summary.content_range&.max.to_i,
}
render json: success_json
else
hijack do
summary = TopicSummarization.new(strategy).summarize(topic, current_user, opts)
render_serialized(summary, TopicSummarySerializer)
end
end
end