UX: Avoid introductory phrases and summarize topics without replies (#848)

This commit is contained in:
Roman Rizzi 2024-10-21 17:53:48 -03:00 committed by GitHub
parent 6d504ab80d
commit 3533814870
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 11 deletions

View File

@ -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

View File

@ -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 <ai></ai> 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 <ai></ai> tags.
TEXT
prompt