diff --git a/lib/summarization/fold_content.rb b/lib/summarization/fold_content.rb
index 00b2c80b..b21f2632 100644
--- a/lib/summarization/fold_content.rb
+++ b/lib/summarization/fold_content.rb
@@ -45,16 +45,19 @@ module DiscourseAi
summarize_chunks(initial_chunks, user, opts, &on_partial_blk)
end
+ clean_summary =
+ Nokogiri::HTML5.fragment(result[:summary]).css("ai")&.first&.text || result[:summary]
+
if persist_summaries
AiSummary.store!(
strategy.target,
strategy.type,
llm_model.name,
- result[:summary],
+ clean_summary,
content_to_summarize[:contents].map { |c| c[:id] },
)
else
- AiSummary.new(summarized_text: result[:summary])
+ AiSummary.new(summarized_text: clean_summary)
end
end
diff --git a/lib/summarization/strategies/hot_topic_gists.rb b/lib/summarization/strategies/hot_topic_gists.rb
index 5d4f802b..ad61f2b0 100644
--- a/lib/summarization/strategies/hot_topic_gists.rb
+++ b/lib/summarization/strategies/hot_topic_gists.rb
@@ -95,22 +95,34 @@ module DiscourseAi
- Use the original language of the text.
- Begin directly with the main topic or issue, avoiding introductory phrases.
- Limit the summary to a maximum of 20 words.
+
+ Return the 20-word summary inside tags.
TEXT
- prompt.push(type: :user, content: <<~TEXT.strip)
+ context = +<<~TEXT
### Context:
-
- The conversation began with the following statement:
-
+
#{opts[:content_title].present? ? "The discussion title is: " + opts[:content_title] + ".\n" : ""}
+
+ The conversation began with the following statement:
- #{statements&.pop}
-
- Subsequent discussion includes the following:
+ #{statements&.pop}\n
+ TEXT
- #{statements&.join}
+ if statements.present?
+ context << <<~TEXT
+ Subsequent discussion includes the following:
+
+ #{statements&.join("\n")}
- Your task is to focus on these latest messages, capturing their meaning in the context of the initial post.
+ Your task is to focus on these latest messages, capturing their meaning in the context of the initial statement.
+ TEXT
+ else
+ context << "Your task is to capture the meaning of the initial statement."
+ end
+
+ prompt.push(type: :user, content: <<~TEXT.strip)
+ #{context} Return the 20-word summary inside tags.
TEXT
prompt