Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 5be59b3

Browse files
committed
UX: Avoid introductory phrases and summarize topics without replies
1 parent 6d504ab commit 5be59b3

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

lib/summarization/fold_content.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,19 @@ def summarize(user, &on_partial_blk)
4545
summarize_chunks(initial_chunks, user, opts, &on_partial_blk)
4646
end
4747

48+
clean_summary =
49+
Nokogiri::HTML5.fragment(result[:summary]).css("ai")&.first&.text || result[:summary]
50+
4851
if persist_summaries
4952
AiSummary.store!(
5053
strategy.target,
5154
strategy.type,
5255
llm_model.name,
53-
result[:summary],
56+
clean_summary,
5457
content_to_summarize[:contents].map { |c| c[:id] },
5558
)
5659
else
57-
AiSummary.new(summarized_text: result[:summary])
60+
AiSummary.new(summarized_text: clean_summary)
5861
end
5962
end
6063

lib/summarization/strategies/hot_topic_gists.rb

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,34 @@ def summarize_single_prompt(input, opts)
9595
- Use the original language of the text.
9696
- Begin directly with the main topic or issue, avoiding introductory phrases.
9797
- Limit the summary to a maximum of 20 words.
98+
99+
Return the 20-word summary inside <ai></ai> tags.
98100
TEXT
99101

100-
prompt.push(type: :user, content: <<~TEXT.strip)
102+
context = +<<~TEXT
101103
### Context:
102-
103-
The conversation began with the following statement:
104-
104+
105105
#{opts[:content_title].present? ? "The discussion title is: " + opts[:content_title] + ".\n" : ""}
106+
107+
The conversation began with the following statement:
106108
107-
#{statements&.pop}
108-
109-
Subsequent discussion includes the following:
109+
#{statements&.pop}\n
110+
TEXT
111+
112+
if statements.present?
113+
context << <<~TEXT
114+
Subsequent discussion includes the following:
110115
111-
#{statements&.join}
116+
#{statements&.join("\n")}
112117
113-
Your task is to focus on these latest messages, capturing their meaning in the context of the initial post.
118+
Your task is to focus on these latest messages, capturing their meaning in the context of the initial statement.
119+
TEXT
120+
else
121+
context << "Your task is to capture the meaning of the initial statement."
122+
end
123+
124+
prompt.push(type: :user, content: <<~TEXT.strip)
125+
#{context} Return the 20-word summary inside <ai></ai> tags.
114126
TEXT
115127

116128
prompt

0 commit comments

Comments
 (0)