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

@ -5469,10 +5469,27 @@ RSpec.describe TopicsController do
end
context "for anons" do
it "returns a 404" do
it "returns a 404 if there is no cached summary" do
get "/t/#{topic.id}/strategy-summary.json"
expect(response.status).to eq(403)
expect(response.status).to eq(404)
end
it "returns a cached summary" do
section =
SummarySection.create!(
target: topic,
summarized_text: "test",
algorithm: "test",
original_content_sha: "test",
)
get "/t/#{topic.id}/strategy-summary.json"
expect(response.status).to eq(200)
summary = response.parsed_body
expect(summary["summary"]).to eq(section.summarized_text)
end
end
@ -5498,15 +5515,32 @@ RSpec.describe TopicsController do
end
end
context "when the user is not a member of an allowlited group" do
context "when the user is not a member of an allowlisted group" do
fab!(:user) { Fabricate(:user) }
before { sign_in(user) }
it "return a 404" do
it "return a 404 if there is no cached summary" do
get "/t/#{topic.id}/strategy-summary.json"
expect(response.status).to eq(403)
expect(response.status).to eq(404)
end
it "returns a cached summary" do
section =
SummarySection.create!(
target: topic,
summarized_text: "test",
algorithm: "test",
original_content_sha: "test",
)
get "/t/#{topic.id}/strategy-summary.json"
expect(response.status).to eq(200)
summary = response.parsed_body
expect(summary["summary"]).to eq(section.summarized_text)
end
end
end