Class: LlmDocsBuilder::OutputFormatter Private
- Inherits:
-
Object
- Object
- LlmDocsBuilder::OutputFormatter
- Defined in:
- lib/llm_docs_builder/output_formatter.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Formats output for CLI display
Provides formatting utilities for displaying comparison results, byte sizes, and numbers in a user-friendly way.
Constant Summary collapse
- NO_AI_VERSION_THRESHOLD =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Threshold percentage below which we consider there’s no AI-optimized version
5
Class Method Summary collapse
-
.display_comparison_results(result) ⇒ Object
private
Display formatted comparison results.
-
.display_increase(result) ⇒ Object
private
Display increase statistics.
-
.display_no_ai_version_message(result) ⇒ Object
private
Display message when no dedicated AI version is detected.
-
.display_reduction(result) ⇒ Object
private
Display reduction statistics.
-
.format_bytes(bytes) ⇒ String
private
Format bytes into human-readable string.
-
.format_number(number) ⇒ String
private
Format number with comma separators for readability.
Class Method Details
.display_comparison_results(result) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Display formatted comparison results
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/llm_docs_builder/output_formatter.rb', line 45 def self.display_comparison_results(result) puts '' puts '=' * 60 puts 'Context Window Comparison' puts '=' * 60 puts '' puts "Human version: #{format_bytes(result[:human_size])} (~#{format_number(result[:human_tokens])} tokens)" puts " Source: #{result[:human_source]}" puts '' puts "AI version: #{format_bytes(result[:ai_size])} (~#{format_number(result[:ai_tokens])} tokens)" puts " Source: #{result[:ai_source]}" puts '' puts '-' * 60 if result[:reduction_bytes].positive? display_reduction(result) # Detect if there's no dedicated AI version if result[:reduction_percent] < NO_AI_VERSION_THRESHOLD (result) end elsif result[:reduction_bytes].negative? display_increase(result) else puts 'Same size' (result) end puts '=' * 60 puts '' end |
.display_increase(result) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Display increase statistics
91 92 93 94 95 96 97 98 99 |
# File 'lib/llm_docs_builder/output_formatter.rb', line 91 def self.display_increase(result) increase_bytes = result[:reduction_bytes].abs increase_percent = result[:reduction_percent].abs token_increase = result[:token_reduction].abs token_increase_percent = result[:token_reduction_percent].abs puts "Increase: #{format_bytes(increase_bytes)} (#{increase_percent}%)" puts "Token increase: #{format_number(token_increase)} tokens (#{token_increase_percent}%)" puts "Factor: #{result[:factor]}x larger" end |
.display_no_ai_version_message(result) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Display message when no dedicated AI version is detected
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/llm_docs_builder/output_formatter.rb', line 105 def self.(result) puts '' puts 'WARNING: NO DEDICATED AI VERSION DETECTED' puts '' puts 'The server is returning nearly identical content to both human and AI' puts 'User-Agents, indicating no AI-optimized version is currently served.' puts '' puts 'POTENTIAL SAVINGS WITH AI OPTIMIZATION:' puts '' puts 'Based on typical documentation optimization results, you could expect:' puts ' • 67-95% token reduction (average 83%)' puts ' • 3-20x smaller file sizes' puts ' • Faster LLM processing times' puts ' • Reduced API costs for AI queries' puts ' • Improved response accuracy' puts '' puts "For this page specifically (~#{format_number(result[:human_tokens])} tokens):" puts " • Estimated savings: ~#{format_number((result[:human_tokens] * 0.83).round)} tokens (83% reduction)" puts " • Could reduce to: ~#{format_number((result[:human_tokens] * 0.17).round)} tokens" puts " • Potential size: ~#{format_bytes((result[:human_size] * 0.17).round)}" puts '' puts 'HOW TO IMPLEMENT AI-OPTIMIZED DOCUMENTATION:' puts '' puts '1. Transform your docs with llm-docs-builder:' puts ' llm-docs-builder bulk-transform --docs ./docs --config llm-docs-builder.yml' puts '' puts '2. Configure your web server to serve .md files to AI bots:' puts ' See: https://github.com/mensfeld/llm-docs-builder#serving-optimized-docs' puts '' puts '3. Measure your actual savings:' puts ' llm-docs-builder compare --url <your-url> --file <local-md>' puts '' end |
.display_reduction(result) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Display reduction statistics
81 82 83 84 85 |
# File 'lib/llm_docs_builder/output_formatter.rb', line 81 def self.display_reduction(result) puts "Reduction: #{format_bytes(result[:reduction_bytes])} (#{result[:reduction_percent]}%)" puts "Token savings: #{format_number(result[:token_reduction])} tokens (#{result[:token_reduction_percent]}%)" puts "Factor: #{result[:factor]}x smaller" end |
.format_bytes(bytes) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Format bytes into human-readable string
21 22 23 24 25 26 27 28 29 |
# File 'lib/llm_docs_builder/output_formatter.rb', line 21 def self.format_bytes(bytes) if bytes < 1024 "#{bytes} bytes" elsif bytes < 1024 * 1024 "#{(bytes / 1024.0).round(1)} KB" else "#{(bytes / (1024.0 * 1024)).round(2)} MB" end end |
.format_number(number) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Format number with comma separators for readability
38 39 40 |
# File 'lib/llm_docs_builder/output_formatter.rb', line 38 def self.format_number(number) number.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse end |