Module: RubyLLM::Text::KeyPoints
- Defined in:
- lib/ruby_llm/text/key_points.rb
Class Method Summary collapse
- .build_prompt(text, max_points:, format:) ⇒ Object
- .call(text, max_points: nil, format: :sentences, model: nil, **options) ⇒ Object
- .parse_response(response, format) ⇒ Object
Class Method Details
.build_prompt(text, max_points:, format:) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ruby_llm/text/key_points.rb', line 16 def self.build_prompt(text, max_points:, format:) count_instruction = max_points ? " (maximum #{max_points} points)" : "" format_instruction = case format when :bullets "Format each point with a bullet (•) at the start." when :numbers "Format as a numbered list (1. 2. 3. etc.)." when :sentences "Format as complete sentences, one per line." else "Format as complete sentences, one per line." end <<~PROMPT Extract the key points from the following text#{count_instruction}. #{format_instruction} Return only the key points, no preamble or explanation. Each point should be on a separate line. Text: #{text} PROMPT end |
.call(text, max_points: nil, format: :sentences, model: nil, **options) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/ruby_llm/text/key_points.rb', line 4 def self.call(text, max_points: nil, format: :sentences, model: nil, **) model ||= RubyLLM::Text.config.model_for(:key_points) prompt = build_prompt(text, max_points: max_points, format: format) response = Base.call_llm(prompt, model: model, **) # Parse response into array of strings parse_response(response, format) end |
.parse_response(response, format) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ruby_llm/text/key_points.rb', line 41 def self.parse_response(response, format) lines = response.strip.split("\n").map(&:strip).reject(&:empty?) # Clean up formatting markers regardless of format for robust output lines.map do |line| # Always clean common formatting markers to handle LLM inconsistencies cleaned = line.gsub(/^[•\*\-]\s*/, "") # Remove bullets cleaned = cleaned.gsub(/^\d+\.\s*/, "") # Remove numbers cleaned end end |