| 
									
										
										
										
											2023-06-27 12:26:33 -03:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module DiscourseAi | 
					
						
							|  |  |  |   module Summarization | 
					
						
							|  |  |  |     module Strategies | 
					
						
							|  |  |  |       class TruncateContent < ::Summarization::Base | 
					
						
							|  |  |  |         def initialize(completion_model) | 
					
						
							|  |  |  |           @completion_model = completion_model | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         attr_reader :completion_model | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         delegate :correctly_configured?, | 
					
						
							|  |  |  |                  :display_name, | 
					
						
							|  |  |  |                  :configuration_hint, | 
					
						
							|  |  |  |                  :model, | 
					
						
							|  |  |  |                  to: :completion_model | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-11 15:08:54 -03:00
										 |  |  |         def summarize(content, &on_partial_blk) | 
					
						
							| 
									
										
										
										
											2023-06-27 12:26:33 -03:00
										 |  |  |           opts = content.except(:contents) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           { | 
					
						
							| 
									
										
										
										
											2023-08-11 15:08:54 -03:00
										 |  |  |             summary: | 
					
						
							|  |  |  |               completion_model.summarize_with_truncation(content[:contents], opts, &on_partial_blk), | 
					
						
							| 
									
										
										
										
											2023-06-27 12:26:33 -03:00
										 |  |  |             chunks: [], | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |