Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions render.rb
Original file line number Diff line number Diff line change
Expand Up @@ -634,13 +634,25 @@ def strip_incomplete_summary_sentences(summary)
sentences.join(' ')
end

def deduplicate_summary_sentences(summary)
seen = {}
split_summary_sentences(summary).each_with_object([]) do |sentence, unique|
normalized = sentence.downcase.split.join(' ')
next if seen[normalized]

seen[normalized] = true
unique << sentence
end.join(' ')
end

def format_summary(text, max_words: nil)
summary = text.to_s.split.join(' ')
summary = summary.sub(/\A(?:summary:\s*)/i, '')
summary = summary.sub(/\Athe (?:supplied )?text (?:highlights|describes|reports|covers|notes|discusses)\s+/i, '')
summary = summary.sub(/\Arecent updates (?:highlight|include)\s+/i, '')
summary = summary.sub(/\A[^.:]{1,80}\bis seeing several key updates:\s*/i, '')
summary = strip_incomplete_summary_sentences(summary)
summary = deduplicate_summary_sentences(summary)
summary = strip_generic_summary_closer(summary)
summary = summary.gsub(/\[([^\]]{1,100})\]\([^)[:space:]]{1,200}\)/, '\1')
summary = summary.gsub(/\*\*([^*]{1,200})\*\*/, '\1')
Expand Down
3 changes: 3 additions & 0 deletions test/render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ def test_format_summary_enforces_plain_paragraph_contract
assert_equal 'First complete sentence. Final complete sentence.',
format_summary('First complete sentence. Cut off on We…. Final complete sentence.'),
'sentences containing truncated text must be removed'
assert_equal 'One update. Another update.',
format_summary('One update. Another update. One update.'),
'repeated model sentences must be emitted only once'
end

def test_summarize_news_skips_ai_without_local_endpoint
Expand Down