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

@ -1,24 +1,67 @@
# frozen_string_literal: true
describe Summarization::Base do
subject(:summarization) { described_class.new }
fab!(:user) { Fabricate(:user) }
fab!(:group) { Fabricate(:group) }
fab!(:topic) { Fabricate(:topic) }
before { group.add(user) }
let(:plugin) { Plugin::Instance.new }
describe "#can_request_summaries?" do
it "returns true if the user group is present in the custom_summarization_allowed_groups_map setting" do
SiteSetting.custom_summarization_allowed_groups = group.id
before do
group.add(user)
expect(summarization.can_request_summaries?(user)).to eq(true)
strategy = DummyCustomSummarization.new("dummy")
plugin.register_summarization_strategy(strategy)
SiteSetting.summarization_strategy = strategy.model
end
describe "#can_see_summary?" do
context "when the user cannot generate a summary" do
before { SiteSetting.custom_summarization_allowed_groups = "" }
it "returns false" do
SiteSetting.custom_summarization_allowed_groups = ""
expect(described_class.can_see_summary?(topic, user)).to eq(false)
end
it "returns true if there is a cached summary" do
SummarySection.create!(
target: topic,
summarized_text: "test",
original_content_sha: "123",
algorithm: "test",
meta_section_id: nil,
)
expect(described_class.can_see_summary?(topic, user)).to eq(true)
end
end
it "returns false if the user group is not present in the custom_summarization_allowed_groups_map setting" do
SiteSetting.custom_summarization_allowed_groups = ""
context "when the user can generate a summary" do
before { SiteSetting.custom_summarization_allowed_groups = group.id }
expect(summarization.can_request_summaries?(user)).to eq(false)
it "returns true if the user group is present in the custom_summarization_allowed_groups_map setting" do
expect(described_class.can_see_summary?(topic, user)).to eq(true)
end
end
context "when there is no user" do
it "returns false for anons" do
expect(described_class.can_see_summary?(topic, nil)).to eq(false)
end
it "returns true for anons when there is a cached summary" do
SummarySection.create!(
target: topic,
summarized_text: "test",
original_content_sha: "123",
algorithm: "test",
meta_section_id: nil,
)
expect(described_class.can_see_summary?(topic, nil)).to eq(true)
end
end
end
end