A platform for community discussion. Free, open, simple.
FEATURE: Prefer topic_embed's cached content when summarizing (#25190)
Roman Rizzi47597219b101
diff --git a/app/services/topic_summarization.rb b/app/services/topic_summarization.rbindex 752066a7d2e..46797b6a9f2 100644--- a/app/services/topic_summarization.rb+++ b/app/services/topic_summarization.rb@@ -32,7 +32,13 @@ class TopicSummarization}targets_data.map do |(pn, raw, username)|- content[:contents] << { poster: username, id: pn, text: raw }+ raw_text = raw++ if pn == 1 && topic.topic_embed&.embed_content_cache.present?+ raw_text = topic.topic_embed&.embed_content_cache+ end++ content[:contents] << { poster: username, id: pn, text: raw_text }endsummarization_result = strategy.summarize(content, user, &on_partial_blk)diff --git a/spec/fabricators/topic_embed_fabricator.rb b/spec/fabricators/topic_embed_fabricator.rbindex 7aace7a2a6f..628a3899eee 100644--- a/spec/fabricators/topic_embed_fabricator.rb+++ b/spec/fabricators/topic_embed_fabricator.rb@@ -2,5 +2,6 @@Fabricator(:topic_embed) dopost+ embed_url "http://eviltrout.com/123"topic { |te| te[:post].topic }enddiff --git a/spec/services/topic_summarization_spec.rb b/spec/services/topic_summarization_spec.rbindex 3446013f1e9..7a282d2506a 100644--- a/spec/services/topic_summarization_spec.rb+++ b/spec/services/topic_summarization_spec.rb@@ -100,6 +100,24 @@ describe TopicSummarization dosection = summarization.summarize(topic, user)expect(section.summarized_text).to eq(cached_summary_text)end++ context "when the topic has embed content cached" do+ it "embed content is used instead of the raw text" do+ topic_embed =+ Fabricate(+ :topic_embed,+ topic: topic,+ embed_content_cache: "<p>hello world new post :D</p>",+ )++ summarization.summarize(topic, user)++ first_post_data =+ strategy.content[:contents].detect { |c| c[:id] == topic.first_post.post_number }++ expect(first_post_data[:text]).to eq(topic_embed.embed_content_cache)+ end+ endendcontext "when the content was summarized in multiple chunks" dodiff --git a/spec/support/dummy_custom_summarization.rb b/spec/support/dummy_custom_summarization.rbindex 096fa4b0d37..45fd1166524 100644--- a/spec/support/dummy_custom_summarization.rb+++ b/spec/support/dummy_custom_summarization.rb@@ -21,7 +21,10 @@ class DummyCustomSummarization < Summarization::Base"dummy"end- def summarize(_content, _user)+ def summarize(content, _user)+ @content = content@summarization_result.tap { |result| yield(result[:summary]) if block_given? }end++ attr_reader :contentend