@@ -9,13 +9,13 @@ module Summarization
99 # into a final version.
1010 #
1111 class FoldContent
12- def initialize ( llm , strategy , persist_summaries : true )
13- @llm = llm
12+ def initialize ( bot , strategy , persist_summaries : true )
13+ @bot = bot
1414 @strategy = strategy
1515 @persist_summaries = persist_summaries
1616 end
1717
18- attr_reader :llm , :strategy
18+ attr_reader :bot , :strategy
1919
2020 # @param user { User } - User object used for auditing usage.
2121 # @param &on_partial_blk { Block - Optional } - The passed block will get called with the LLM partial response alongside a cancel function.
@@ -76,7 +76,7 @@ def delete_cached_summaries!
7676 attr_reader :persist_summaries
7777
7878 def llm_model
79- llm . llm_model
79+ bot . llm . llm_model
8080 end
8181
8282 def content_to_summarize
@@ -118,20 +118,29 @@ def fold(items, summary, cursor, user, &on_partial_blk)
118118 end
119119 end
120120
121- prompt =
122- (
123- if summary . blank?
124- strategy . first_summary_prompt ( iteration_content )
125- else
126- strategy . summary_extension_prompt ( summary , iteration_content )
127- end
128- )
121+ context = {
122+ target_url : "#{ Discourse . base_path } /t/-/#{ strategy . target . id } " ,
123+ skip_tool_details : true ,
124+ user : user ,
125+ feature_name : strategy . feature ,
126+ }
127+ context [ :conversation_context ] = (
128+ if summary . blank?
129+ strategy . first_summary_messages ( iteration_content )
130+ else
131+ strategy . summary_extension_messages ( summary , iteration_content )
132+ end
133+ )
129134
130135 if cursor == items . length
131- llm . generate ( prompt , user : user , feature_name : strategy . feature , & on_partial_blk )
136+ bot . reply ( context , & text_only_update ( & on_partial_blk ) )
132137 else
133- latest_summary =
134- llm . generate ( prompt , user : user , max_tokens : 600 , feature_name : strategy . feature )
138+ context [ :max_tokens ] = 600
139+
140+ latest_summary = +""
141+ update_blk = text_only_update ( Proc . new { |partial , cancel | latest_summary << partial } )
142+ bot . reply ( context , &update_blk )
143+
135144 fold ( items , latest_summary , cursor , user , &on_partial_blk )
136145 end
137146 end
@@ -159,6 +168,12 @@ def truncate(item)
159168
160169 item
161170 end
171+
172+ def text_only_update ( &on_partial_blk )
173+ Proc . new do |partial , cancel , placeholder , type |
174+ on_partial_blk . call ( partial , cancel ) if type . blank?
175+ end
176+ end
162177 end
163178 end
164179end
0 commit comments