Module: RubyLLM::Text::Summarize

Defined in:
lib/ruby_llm/text/summarize.rb

Constant Summary collapse

LENGTHS =
{
  short: "1-2 sentences",
  medium: "3-5 sentences",
  detailed: "1-2 paragraphs"
}.freeze

Class Method Summary collapse

Class Method Details

.build_prompt(text, length:, max_words:) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruby_llm/text/summarize.rb', line 19

def self.build_prompt(text, length:, max_words:)
  length_instruction = LENGTHS[length] || length.to_s
  word_limit = max_words ? " (maximum #{max_words} words)" : ""

  "    Summarize the following text.\n    Length: \#{length_instruction}\#{word_limit}\n    Return only the summary, no preamble or explanation.\n\n    Text:\n    \#{text}\n  PROMPT\nend\n"

.call(text, length: :medium, max_words: nil, model: nil, **options) ⇒ Object



10
11
12
13
14
15
# File 'lib/ruby_llm/text/summarize.rb', line 10

def self.call(text, length: :medium, max_words: nil, model: nil, **options)
  model ||= RubyLLM::Text.config.model_for(:summarize)

  prompt = build_prompt(text, length: length, max_words: max_words)
  Base.call_llm(prompt, model: model, **options)
end