2024-10-15 12:53:26 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module DiscourseAi
|
|
|
|
module Summarization
|
|
|
|
module Strategies
|
|
|
|
# Objects inheriting from this class will get passed as a dependency to `DiscourseAi::Summarization::FoldContent`.
|
|
|
|
# This collaborator knows how to source the content to summarize and the prompts used in the process,
|
|
|
|
# one for summarizing a chunk and another for concatenating them if necessary.
|
|
|
|
class Base
|
|
|
|
def initialize(target)
|
|
|
|
@target = target
|
|
|
|
end
|
|
|
|
|
2024-10-25 10:51:17 -04:00
|
|
|
attr_reader :target, :opts
|
2024-10-15 12:53:26 -04:00
|
|
|
|
|
|
|
# The summary type differentiates instances of `AiSummary` pointing to a single target.
|
|
|
|
# See the `summary_type` enum for available options.
|
|
|
|
def type
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2024-10-25 10:51:17 -04:00
|
|
|
# @returns { Array<Hash> } - Content to summarize.
|
2024-10-15 12:53:26 -04:00
|
|
|
#
|
2024-10-25 10:51:17 -04:00
|
|
|
# This method returns an array of hashes with the content to summarize using the following structure:
|
2024-10-15 12:53:26 -04:00
|
|
|
#
|
|
|
|
# {
|
|
|
|
# poster: A way to tell who write the content,
|
|
|
|
# id: A number to signal order,
|
|
|
|
# text: Text to summarize
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
def targets_data
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2024-10-25 10:51:17 -04:00
|
|
|
# @returns { DiscourseAi::Completions::Prompt } - Prompt passed to the LLM when extending an existing summary.
|
2024-10-31 11:17:42 -04:00
|
|
|
def summary_extension_prompt(_summary, _texts_to_summarize)
|
2024-10-15 12:53:26 -04:00
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
|
2024-10-25 10:51:17 -04:00
|
|
|
# @returns { DiscourseAi::Completions::Prompt } - Prompt passed to the LLM for summarizing a single chunk of content.
|
2024-10-31 11:17:42 -04:00
|
|
|
def first_summary_prompt(_input)
|
2024-10-15 12:53:26 -04:00
|
|
|
raise NotImplementedError
|
|
|
|
end
|
2024-10-29 07:45:14 -04:00
|
|
|
|
|
|
|
# We'll pass this as the feature_name when doing LLM calls.
|
|
|
|
def feature
|
|
|
|
"summarize"
|
|
|
|
end
|
2024-10-15 12:53:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|