mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Prefer topic_embed's cached content when summarizing (#25190)
This commit is contained in:
parent
2e0ec679c5
commit
47597219b1
@ -32,7 +32,13 @@ class TopicSummarization
|
|||||||
}
|
}
|
||||||
|
|
||||||
targets_data.map do |(pn, raw, username)|
|
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 }
|
||||||
end
|
end
|
||||||
|
|
||||||
summarization_result = strategy.summarize(content, user, &on_partial_blk)
|
summarization_result = strategy.summarize(content, user, &on_partial_blk)
|
||||||
|
@ -2,5 +2,6 @@
|
|||||||
|
|
||||||
Fabricator(:topic_embed) do
|
Fabricator(:topic_embed) do
|
||||||
post
|
post
|
||||||
|
embed_url "http://eviltrout.com/123"
|
||||||
topic { |te| te[:post].topic }
|
topic { |te| te[:post].topic }
|
||||||
end
|
end
|
||||||
|
@ -100,6 +100,24 @@ describe TopicSummarization do
|
|||||||
section = summarization.summarize(topic, user)
|
section = summarization.summarize(topic, user)
|
||||||
expect(section.summarized_text).to eq(cached_summary_text)
|
expect(section.summarized_text).to eq(cached_summary_text)
|
||||||
end
|
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
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "when the content was summarized in multiple chunks" do
|
context "when the content was summarized in multiple chunks" do
|
||||||
|
@ -21,7 +21,10 @@ class DummyCustomSummarization < Summarization::Base
|
|||||||
"dummy"
|
"dummy"
|
||||||
end
|
end
|
||||||
|
|
||||||
def summarize(_content, _user)
|
def summarize(content, _user)
|
||||||
|
@content = content
|
||||||
@summarization_result.tap { |result| yield(result[:summary]) if block_given? }
|
@summarization_result.tap { |result| yield(result[:summary]) if block_given? }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attr_reader :content
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user