This repository was archived by the owner on Jul 22, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +26
-11
lines changed Expand file tree Collapse file tree 2 files changed +26
-11
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments