yuno-proofreader 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/lib/yuno/proofreader/analysis/adjustments.rb +30 -32
  4. data/lib/yuno/proofreader/analysis/crawler.rb +71 -73
  5. data/lib/yuno/proofreader/analysis/entries.rb +52 -54
  6. data/lib/yuno/proofreader/analysis/extractor.rb +162 -164
  7. data/lib/yuno/proofreader/analysis/graph.rb +86 -88
  8. data/lib/yuno/proofreader/analysis/judge.rb +80 -82
  9. data/lib/yuno/proofreader/analysis/judge_prompt.rb +50 -52
  10. data/lib/yuno/proofreader/analysis/judgments.rb +50 -52
  11. data/lib/yuno/proofreader/analysis/links.rb +44 -46
  12. data/lib/yuno/proofreader/analysis/list_order.rb +20 -22
  13. data/lib/yuno/proofreader/analysis/reasons.rb +44 -43
  14. data/lib/yuno/proofreader/analysis/report.rb +79 -81
  15. data/lib/yuno/proofreader/analysis/runner.rb +133 -135
  16. data/lib/yuno/proofreader/analysis/scorer.rb +97 -99
  17. data/lib/yuno/proofreader/analysis/settings.rb +65 -67
  18. data/lib/yuno/proofreader/analysis/signals.rb +77 -79
  19. data/lib/yuno/proofreader/analysis/structured_data.rb +40 -42
  20. data/lib/yuno/proofreader/analysis/url_tree.rb +34 -36
  21. data/lib/yuno/proofreader/analysis/weights.rb +67 -69
  22. data/lib/yuno/proofreader/audit/agenda.rb +63 -65
  23. data/lib/yuno/proofreader/audit/agenda_report.rb +44 -46
  24. data/lib/yuno/proofreader/audit/answers.rb +53 -55
  25. data/lib/yuno/proofreader/audit/attempt.rb +50 -52
  26. data/lib/yuno/proofreader/audit/batch.rb +49 -49
  27. data/lib/yuno/proofreader/audit/batch_report.rb +62 -64
  28. data/lib/yuno/proofreader/audit/cadence.rb +47 -49
  29. data/lib/yuno/proofreader/audit/instructions.rb +15 -17
  30. data/lib/yuno/proofreader/audit/log_fields.rb +16 -18
  31. data/lib/yuno/proofreader/audit/prompt.rb +118 -120
  32. data/lib/yuno/proofreader/audit/report.rb +116 -118
  33. data/lib/yuno/proofreader/audit/runner.rb +150 -152
  34. data/lib/yuno/proofreader/audit/schemas.rb +49 -0
  35. data/lib/yuno/proofreader/audit/steps.rb +46 -48
  36. data/lib/yuno/proofreader/cli/analysis_commands.rb +36 -38
  37. data/lib/yuno/proofreader/cli/audit_commands.rb +89 -91
  38. data/lib/yuno/proofreader/cli/command_log.rb +34 -36
  39. data/lib/yuno/proofreader/cli/flags.rb +33 -35
  40. data/lib/yuno/proofreader/cli/generate_commands.rb +99 -101
  41. data/lib/yuno/proofreader/cli/init_command.rb +123 -125
  42. data/lib/yuno/proofreader/cli/model_commands.rb +35 -37
  43. data/lib/yuno/proofreader/cli/queue_commands.rb +79 -81
  44. data/lib/yuno/proofreader/cli/sheet_commands.rb +42 -44
  45. data/lib/yuno/proofreader/cli.rb +197 -199
  46. data/lib/yuno/proofreader/config.rb +13 -17
  47. data/lib/yuno/proofreader/context.rb +45 -50
  48. data/lib/yuno/proofreader/env_file.rb +52 -56
  49. data/lib/yuno/proofreader/errors.rb +7 -9
  50. data/lib/yuno/proofreader/findings/finding.rb +73 -75
  51. data/lib/yuno/proofreader/findings/matching.rb +21 -23
  52. data/lib/yuno/proofreader/findings/merger.rb +35 -37
  53. data/lib/yuno/proofreader/findings/outline.rb +50 -52
  54. data/lib/yuno/proofreader/findings/plan.rb +14 -16
  55. data/lib/yuno/proofreader/findings/reconciler.rb +170 -172
  56. data/lib/yuno/proofreader/findings/source.rb +54 -56
  57. data/lib/yuno/proofreader/findings/text.rb +24 -26
  58. data/lib/yuno/proofreader/generate/cache.rb +54 -56
  59. data/lib/yuno/proofreader/generate/collector.rb +98 -100
  60. data/lib/yuno/proofreader/generate/describe.rb +18 -20
  61. data/lib/yuno/proofreader/generate/llm/prompt.rb +50 -52
  62. data/lib/yuno/proofreader/generate/llm/reader.rb +84 -86
  63. data/lib/yuno/proofreader/generate/llm/wording.rb +12 -14
  64. data/lib/yuno/proofreader/generate/llms_builder.rb +36 -38
  65. data/lib/yuno/proofreader/generate/llms_report.rb +82 -84
  66. data/lib/yuno/proofreader/generate/llms_txt.rb +99 -101
  67. data/lib/yuno/proofreader/generate/llms_writer.rb +43 -45
  68. data/lib/yuno/proofreader/generate/outline.rb +67 -69
  69. data/lib/yuno/proofreader/generate/passage.rb +41 -43
  70. data/lib/yuno/proofreader/generate/saved_answer.rb +42 -44
  71. data/lib/yuno/proofreader/http/client.rb +94 -96
  72. data/lib/yuno/proofreader/http/net_http_transport.rb +35 -37
  73. data/lib/yuno/proofreader/http/robots.rb +51 -53
  74. data/lib/yuno/proofreader/init/ask.rb +45 -47
  75. data/lib/yuno/proofreader/init/detector.rb +75 -77
  76. data/lib/yuno/proofreader/init/interview.rb +155 -157
  77. data/lib/yuno/proofreader/init/parsing.rb +37 -39
  78. data/lib/yuno/proofreader/init/web.rb +22 -24
  79. data/lib/yuno/proofreader/llm/client.rb +118 -113
  80. data/lib/yuno/proofreader/llm/defaults.rb +10 -12
  81. data/lib/yuno/proofreader/llm/errors.rb +18 -18
  82. data/lib/yuno/proofreader/llm/factory.rb +34 -36
  83. data/lib/yuno/proofreader/llm/handoff.rb +86 -88
  84. data/lib/yuno/proofreader/llm/http_transport.rb +25 -27
  85. data/lib/yuno/proofreader/llm/json_text.rb +12 -14
  86. data/lib/yuno/proofreader/llm/provider.rb +49 -51
  87. data/lib/yuno/proofreader/llm/providers/gemini.rb +111 -111
  88. data/lib/yuno/proofreader/llm/providers/manual.rb +34 -36
  89. data/lib/yuno/proofreader/llm/providers.rb +17 -19
  90. data/lib/yuno/proofreader/llm/types.rb +6 -8
  91. data/lib/yuno/proofreader/llm/usage.rb +8 -10
  92. data/lib/yuno/proofreader/log.rb +88 -96
  93. data/lib/yuno/proofreader/pages/fetcher.rb +53 -55
  94. data/lib/yuno/proofreader/pages/report.rb +37 -39
  95. data/lib/yuno/proofreader/pages/snapshot.rb +32 -34
  96. data/lib/yuno/proofreader/pages/trimmer.rb +23 -25
  97. data/lib/yuno/proofreader/settings_file.rb +35 -38
  98. data/lib/yuno/proofreader/site.rb +52 -54
  99. data/lib/yuno/proofreader/site_reader.rb +122 -124
  100. data/lib/yuno/proofreader/sitemap/aligner.rb +58 -60
  101. data/lib/yuno/proofreader/sitemap/importer.rb +19 -21
  102. data/lib/yuno/proofreader/sitemap/loader.rb +95 -97
  103. data/lib/yuno/proofreader/sitemap/mismatch.rb +53 -55
  104. data/lib/yuno/proofreader/sitemap/pairer.rb +171 -173
  105. data/lib/yuno/proofreader/sitemap/parser.rb +50 -52
  106. data/lib/yuno/proofreader/sitemap/report.rb +72 -74
  107. data/lib/yuno/proofreader/store/cells.rb +55 -49
  108. data/lib/yuno/proofreader/store/gateways/csv.rb +53 -56
  109. data/lib/yuno/proofreader/store/gateways/google.rb +152 -158
  110. data/lib/yuno/proofreader/store/memory.rb +60 -64
  111. data/lib/yuno/proofreader/store/records.rb +18 -20
  112. data/lib/yuno/proofreader/store/schema.rb +85 -89
  113. data/lib/yuno/proofreader/store/sheets.rb +132 -145
  114. data/lib/yuno/proofreader/store/tab_setup.rb +51 -54
  115. data/lib/yuno/proofreader/version.rb +1 -1
  116. data/lib/yuno/proofreader.rb +3 -4
  117. data/proofreader.example.yml +15 -10
  118. metadata +3 -2
@@ -1,113 +1,111 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Yuno
4
- module Proofreader
5
- module Generate
6
- module Wording
7
- # Reads the answer of the model. There is no limit on how long a summary or a text may be. Whatever does not
8
- # hold up is left out and noted: a text that does not end in a whole sentence, or that has a number its page
9
- # does not have. A page left without a text shows the description it already has.
10
- class Reader
11
- HEADING_MAX = 100
12
- NUMBER = /\d+(?:[.,]\d+)?/
13
- MARKDOWN_START = /\A[#>*\-\s]+/
14
- SENTENCE_END = /[.!?]["'”’»)]*\z/
15
- ELLIPSIS = /(?:\.\.\.|…)["'”’»)]*\z/
16
-
17
- def self.call(data, outline) = new(data, outline).call
18
-
19
- def initialize(data, outline)
20
- @data = data
21
- @sections = outline.all_sections.to_h { |section| [section.id, section] }
22
- @items = outline.items.to_h { |item| [item.id, item] }
23
- @notes = []
24
- end
3
+ module Yuno::Proofreader
4
+ module Generate
5
+ module Wording
6
+ # Reads the answer of the model. There is no limit on how long a summary or a text may be. Whatever does not
7
+ # hold up is left out and noted: a text that does not end in a whole sentence, or that has a number its page
8
+ # does not have. A page left without a text shows the description it already has.
9
+ class Reader
10
+ HEADING_MAX = 100
11
+ NUMBER = /\d+(?:[.,]\d+)?/
12
+ MARKDOWN_START = /\A[#>*\-\s]+/
13
+ SENTENCE_END = /[.!?]["'”’»)]*\z/
14
+ ELLIPSIS = /(?:\.\.\.|…)["'”’»)]*\z/
15
+
16
+ def self.call(data, outline) = new(data, outline).call
17
+
18
+ def initialize(data, outline)
19
+ @data = data
20
+ @sections = outline.all_sections.to_h { |section| [section.id, section] }
21
+ @items = outline.items.to_h { |item| [item.id, item] }
22
+ @notes = []
23
+ end
25
24
 
26
- def call
27
- headings = {}
28
- summaries = {}
29
- entries("sections") do |entry|
30
- section = @sections[entry["id"].to_s]
31
- next skip("section #{entry['id'].inspect} is not in the outline") unless section
32
-
33
- heading = heading_of(entry["heading"], section)
34
- summary = summary_of(entry["summary"], section)
35
- headings[section.id] = heading if heading
36
- summaries[section.id] = summary if summary
37
- end
38
- Result.new(headings:, summaries:, texts: texts, notes: @notes)
25
+ def call
26
+ headings = {}
27
+ summaries = {}
28
+ entries("sections") do |entry|
29
+ section = @sections[entry["id"].to_s]
30
+ next skip("section #{entry['id'].inspect} is not in the outline") unless section
31
+
32
+ heading = heading_of(entry["heading"], section)
33
+ summary = summary_of(entry["summary"], section)
34
+ headings[section.id] = heading if heading
35
+ summaries[section.id] = summary if summary
39
36
  end
37
+ Result.new(headings:, summaries:, texts: texts, notes: @notes)
38
+ end
40
39
 
41
- private
40
+ private
42
41
 
43
- def entries(key)
44
- list = @data.is_a?(Hash) ? @data[key] : nil
45
- return skip("the answer has no list of #{key}") unless list.is_a?(Array)
42
+ def entries(key)
43
+ list = @data.is_a?(Hash) ? @data[key] : nil
44
+ return skip("the answer has no list of #{key}") unless list.is_a?(Array)
46
45
 
47
- list.each { |entry| yield entry if entry.is_a?(Hash) }
48
- end
46
+ list.each { |entry| yield entry if entry.is_a?(Hash) }
47
+ end
49
48
 
50
- def skip(note)
51
- @notes << note
52
- nil
53
- end
49
+ def skip(note)
50
+ @notes << note
51
+ nil
52
+ end
54
53
 
55
- def clean(value) = Findings::Text.collapse(value.to_s).sub(MARKDOWN_START, "").strip
54
+ def clean(value) = Findings::Text.collapse(value.to_s).sub(MARKDOWN_START, "").strip
56
55
 
57
- def whole?(text) = text.match?(SENTENCE_END) && !text.match?(ELLIPSIS)
56
+ def whole?(text) = text.match?(SENTENCE_END) && !text.match?(ELLIPSIS)
58
57
 
59
- def heading_of(value, section)
60
- text = clean(value)
61
- return if text.empty?
58
+ def heading_of(value, section)
59
+ text = clean(value)
60
+ return if text.empty?
62
61
 
63
- long = text.length > HEADING_MAX
64
- long ? skip("#{section.id}: the heading is longer than #{HEADING_MAX} characters") : text
65
- end
62
+ long = text.length > HEADING_MAX
63
+ long ? skip("#{section.id}: the heading is longer than #{HEADING_MAX} characters") : text
64
+ end
66
65
 
67
- def summary_of(value, section)
68
- text = clean(value)
69
- return if text.empty?
70
- return skip("#{section.id}: the summary does not end in a whole sentence") unless whole?(text)
66
+ def summary_of(value, section)
67
+ text = clean(value)
68
+ return if text.empty?
69
+ return skip("#{section.id}: the summary does not end in a whole sentence") unless whole?(text)
71
70
 
72
- invented = numbers_not_in(text, section.all_items)
73
- return text if invented.empty?
71
+ invented = numbers_not_in(text, section.all_items)
72
+ return text if invented.empty?
74
73
 
75
- skip("#{section.id}: the summary has numbers that its pages do not have (#{invented.join(', ')})")
76
- end
74
+ skip("#{section.id}: the summary has numbers that its pages do not have (#{invented.join(', ')})")
75
+ end
77
76
 
78
- def texts
79
- found = {}
80
- entries("pages") do |entry|
81
- item = @items[entry["id"].to_s]
82
- next skip("page #{entry['id'].inspect} is not in the outline") unless item
77
+ def texts
78
+ found = {}
79
+ entries("pages") do |entry|
80
+ item = @items[entry["id"].to_s]
81
+ next skip("page #{entry['id'].inspect} is not in the outline") unless item
83
82
 
84
- text = text_of(entry["text"], item)
85
- found[item.id] = text if text
86
- end
87
- found
83
+ text = text_of(entry["text"], item)
84
+ found[item.id] = text if text
88
85
  end
86
+ found
87
+ end
89
88
 
90
- # The text, an empty string when the model chose to write nothing, or nil when the text cannot be used.
91
- def text_of(value, item)
92
- return skip("page #{item.id}: the text is missing or is not text") unless value.is_a?(String)
93
-
94
- text = clean(value)
95
- return "" if text.empty?
96
- return skip("page #{item.id}: the text does not end in a whole sentence") unless whole?(text)
89
+ # The text, an empty string when the model chose to write nothing, or nil when the text cannot be used.
90
+ def text_of(value, item)
91
+ return skip("page #{item.id}: the text is missing or is not text") unless value.is_a?(String)
97
92
 
98
- invented = numbers_not_in(text, [item])
99
- return text if invented.empty?
93
+ text = clean(value)
94
+ return "" if text.empty?
95
+ return skip("page #{item.id}: the text does not end in a whole sentence") unless whole?(text)
100
96
 
101
- skip("page #{item.id}: the text has numbers that the page does not have (#{invented.join(', ')})")
102
- end
97
+ invented = numbers_not_in(text, [item])
98
+ return text if invented.empty?
103
99
 
104
- def numbers_not_in(text, items)
105
- source = items.flat_map { |item| source_of(item.facts) }.join(" ")
106
- text.scan(NUMBER).uniq.reject { |number| source.match?(/(?<!\d)#{Regexp.escape(number)}(?!\d)/) }
107
- end
100
+ skip("page #{item.id}: the text has numbers that the page does not have (#{invented.join(', ')})")
101
+ end
108
102
 
109
- def source_of(facts) = [facts.name, facts.title, facts.description, *facts.paragraphs, facts.path]
103
+ def numbers_not_in(text, items)
104
+ source = items.flat_map { |item| source_of(item.facts) }.join(" ")
105
+ text.scan(NUMBER).uniq.reject { |number| source.match?(/(?<!\d)#{Regexp.escape(number)}(?!\d)/) }
110
106
  end
107
+
108
+ def source_of(facts) = [facts.name, facts.title, facts.description, *facts.paragraphs, facts.path]
111
109
  end
112
110
  end
113
111
  end
@@ -1,20 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Yuno
4
- module Proofreader
5
- module Generate
6
- # What the model decides for an llms.txt file: headings and summaries of the sections, and the text beside each
7
- # link. Everything is by id. A page that has no entry in texts has no usable text from the model, and an entry
8
- # that is empty means the model chose to write nothing. notes says what was left out of its answer and why.
9
- module Wording
10
- Result = Data.define(:headings, :summaries, :texts, :notes) do
11
- # What is shown beside a link: the model's text (which may be empty on purpose), and without one the
12
- # description the page already has.
13
- def text_for(item) = texts.fetch(item.id) { Describe.fallback(item.facts) }
14
- end
15
-
16
- NONE = Result.new(headings: {}.freeze, summaries: {}.freeze, texts: {}.freeze, notes: [].freeze).freeze
3
+ module Yuno::Proofreader
4
+ module Generate
5
+ # What the model decides for an llms.txt file: headings and summaries of the sections, and the text beside each
6
+ # link. Everything is by id. A page that has no entry in texts has no usable text from the model, and an entry
7
+ # that is empty means the model chose to write nothing. notes says what was left out of its answer and why.
8
+ module Wording
9
+ Result = Data.define(:headings, :summaries, :texts, :notes) do
10
+ # What is shown beside a link: the model's text (which may be empty on purpose), and without one the
11
+ # description the page already has.
12
+ def text_for(item) = texts.fetch(item.id) { Describe.fallback(item.facts) }
17
13
  end
14
+
15
+ NONE = Result.new(headings: {}.freeze, summaries: {}.freeze, texts: {}.freeze, notes: [].freeze).freeze
18
16
  end
19
17
  end
20
18
  end
@@ -1,49 +1,47 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Yuno
4
- module Proofreader
5
- module Generate
6
- # Builds the llms.txt of one language: groups the pages, asks the model for the wording (unless there is no
7
- # client), and renders the file. If the model cannot answer, the file is still made, without summaries, and the
8
- # failure is reported, so the pages that were fetched are not lost.
9
- class LlmsBuilder
10
- # answer is the model's answer, or nil. failure is why there is none, or nil.
11
- Result = Data.define(:text, :pages, :sections, :without_text, :answer, :notes, :failure)
3
+ module Yuno::Proofreader
4
+ module Generate
5
+ # Builds the llms.txt of one language: groups the pages, asks the model for the wording (unless there is no
6
+ # client), and renders the file. If the model cannot answer, the file is still made, without summaries, and the
7
+ # failure is reported, so the pages that were fetched are not lost.
8
+ class LlmsBuilder
9
+ # answer is the model's answer, or nil. failure is why there is none, or nil.
10
+ Result = Data.define(:text, :pages, :sections, :without_text, :answer, :notes, :failure)
12
11
 
13
- def initialize(client: nil, progress: ->(_message) {}, log: Log.null)
14
- @client = client
15
- @progress = progress
16
- @log = log
17
- end
12
+ def initialize(client: nil, progress: ->(_message) {}, log: Log.null)
13
+ @client = client
14
+ @progress = progress
15
+ @log = log
16
+ end
18
17
 
19
- # others: [language code, address] for the llms.txt of each other language, listed at the end of the file.
20
- def call(collected, language:, fallback_title:, others: [])
21
- outline = Grouper.call(collected.entries(language))
22
- home = collected.home.versions[language]
23
- answer, wording, failure = ask(outline, home, language)
24
- text = LlmsTxt.call(outline:, home:, wording:, language:, fallback_title:, others:)
25
- Result.new(text:, pages: outline.items.size, sections: outline.all_sections.size,
26
- without_text: without_text(outline, wording), answer:, notes: wording.notes, failure:)
27
- end
18
+ # others: [language code, address] for the llms.txt of each other language, listed at the end of the file.
19
+ def call(collected, language:, fallback_title:, others: [])
20
+ outline = Grouper.call(collected.entries(language))
21
+ home = collected.home.versions[language]
22
+ answer, wording, failure = ask(outline, home, language)
23
+ text = LlmsTxt.call(outline:, home:, wording:, language:, fallback_title:, others:)
24
+ Result.new(text:, pages: outline.items.size, sections: outline.all_sections.size,
25
+ without_text: without_text(outline, wording), answer:, notes: wording.notes, failure:)
26
+ end
28
27
 
29
- private
28
+ private
30
29
 
31
- def ask(outline, home, language)
32
- return [nil, Wording::NONE, nil] unless @client && !outline.items.empty?
30
+ def ask(outline, home, language)
31
+ return [nil, Wording::NONE, nil] unless @client && !outline.items.empty?
33
32
 
34
- prompt = Wording::Prompt.new(language:)
35
- @progress.call("Wording the #{language} file (this can take a minute)...")
36
- answer = @client.generate(system: prompt.system_prompt, user: prompt.user_message(outline, home))
37
- @progress.call("Got the wording: #{answer.model}, #{answer.seconds.round} s.")
38
- [answer, Wording::Reader.call(answer.data, outline), nil]
39
- rescue LlmError => e
40
- @log.warn("llms wording failed", language:, message: e.message)
41
- [nil, Wording::NONE, e.message]
42
- end
33
+ prompt = Wording::Prompt.new(language:)
34
+ @progress.call("Wording the #{language} file (this can take a minute)...")
35
+ answer = @client.generate(system: prompt.system_prompt, user: prompt.user_message(outline, home))
36
+ @progress.call("Got the wording: #{answer.model}, #{answer.seconds.round} s.")
37
+ [answer, Wording::Reader.call(answer.data, outline), nil]
38
+ rescue LlmError => e
39
+ @log.warn("llms wording failed", language:, message: e.message)
40
+ [nil, Wording::NONE, e.message]
41
+ end
43
42
 
44
- def without_text(outline, wording)
45
- outline.listed.count { |item| wording.text_for(item).empty? }
46
- end
43
+ def without_text(outline, wording)
44
+ outline.listed.count { |item| wording.text_for(item).empty? }
47
45
  end
48
46
  end
49
47
  end
@@ -1,112 +1,110 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Yuno
4
- module Proofreader
5
- module Generate
6
- # The lines generate llms prints: what was read, each file that was written and everything left out.
7
- class LlmsReport
8
- SHOWN_PROBLEMS = 10
9
- SHOWN_NOTES = 5
10
- CLOSING = "Check each file before you upload it: the headings, summaries and link texts that a model " \
11
- "wrote can be wrong."
12
-
13
- # requested: the languages that were asked for. files: the LlmsFile of each one that was written.
14
- # saved_at: when the pages were saved, for a run that used saved pages, or nil.
15
- def initialize(collected:, requested:, files:, saved_at: nil)
16
- @collected = collected
17
- @requested = requested
18
- @files = files
19
- @saved_at = saved_at
20
- end
21
-
22
- def lines
23
- [read_line, "", *@files.map { |file| file_line(file) }, *unwritten_lines, *wording_lines,
24
- *unranked_lines, *problem_lines, "", CLOSING]
25
- end
3
+ module Yuno::Proofreader
4
+ module Generate
5
+ # The lines generate llms prints: what was read, each file that was written and everything left out.
6
+ class LlmsReport
7
+ SHOWN_PROBLEMS = 10
8
+ SHOWN_NOTES = 5
9
+ CLOSING = "Check each file before you upload it: the headings, summaries and link texts that a model " \
10
+ "wrote can be wrong."
11
+
12
+ # requested: the languages that were asked for. files: the LlmsFile of each one that was written.
13
+ # saved_at: when the pages were saved, for a run that used saved pages, or nil.
14
+ def initialize(collected:, requested:, files:, saved_at: nil)
15
+ @collected = collected
16
+ @requested = requested
17
+ @files = files
18
+ @saved_at = saved_at
19
+ end
26
20
 
27
- private
21
+ def lines
22
+ [read_line, "", *@files.map { |file| file_line(file) }, *unwritten_lines, *wording_lines,
23
+ *unranked_lines, *problem_lines, "", CLOSING]
24
+ end
28
25
 
29
- def read_line
30
- return saved_line if @saved_at
26
+ private
31
27
 
32
- hint = partial? ? " (--all reads every page)" : ""
33
- "Read the home page and #{pages_taken}#{hint}."
34
- end
28
+ def read_line
29
+ return saved_line if @saved_at
35
30
 
36
- def saved_line
37
- "Used the pages saved on #{@saved_at} UTC, nothing was fetched: the home page and #{pages_taken}."
38
- end
31
+ hint = partial? ? " (--all reads every page)" : ""
32
+ "Read the home page and #{pages_taken}#{hint}."
33
+ end
39
34
 
40
- def partial? = @collected.pages.size < @collected.considered
35
+ def saved_line
36
+ "Used the pages saved on #{@saved_at} UTC, nothing was fetched: the home page and #{pages_taken}."
37
+ end
41
38
 
42
- def pages_taken
43
- others = @collected.considered
44
- return "all #{others} other pages" unless partial?
39
+ def partial? = @collected.pages.size < @collected.considered
45
40
 
46
- "the #{@collected.pages.size} most important of #{others} other pages"
47
- end
41
+ def pages_taken
42
+ others = @collected.considered
43
+ return "all #{others} other pages" unless partial?
48
44
 
49
- def file_line(file)
50
- built = file.built
51
- detail = ["#{built.pages} pages in #{built.sections} sections"]
52
- detail << "#{built.without_text} without a text" if built.without_text.positive?
53
- detail << model_detail(built.answer) if built.answer
54
- "Wrote #{file.path} (#{detail.join(', ')}). Upload it to #{file.address}"
55
- end
45
+ "the #{@collected.pages.size} most important of #{others} other pages"
46
+ end
56
47
 
57
- def model_detail(answer)
58
- "#{answer.model}, #{answer.seconds.round} s, tokens in/out " \
59
- "#{thousands(answer.input_tokens)} / #{thousands(answer.output_tokens)}"
60
- end
48
+ def file_line(file)
49
+ built = file.built
50
+ detail = ["#{built.pages} pages in #{built.sections} sections"]
51
+ detail << "#{built.without_text} without a text" if built.without_text.positive?
52
+ detail << model_detail(built.answer) if built.answer
53
+ "Wrote #{file.path} (#{detail.join(', ')}). Upload it to #{file.address}"
54
+ end
61
55
 
62
- def thousands(number) = number.to_i.to_s.reverse.scan(/\d{1,3}/).join(",").reverse
56
+ def model_detail(answer)
57
+ "#{answer.model}, #{answer.seconds.round} s, tokens in/out " \
58
+ "#{thousands(answer.input_tokens)} / #{thousands(answer.output_tokens)}"
59
+ end
63
60
 
64
- def unwritten_lines
65
- (@requested - @files.map(&:language)).map do |language|
66
- "No #{language} version could be read, so llms-#{language}.txt was not written."
67
- end
68
- end
61
+ def thousands(number) = number.to_i.to_s.reverse.scan(/\d{1,3}/).join(",").reverse
69
62
 
70
- def wording_lines
71
- lines = @files.flat_map { |file| [*failure_lines(file), *unused_lines(file)] }
72
- lines.empty? ? [] : ["", *lines]
63
+ def unwritten_lines
64
+ (@requested - @files.map(&:language)).map do |language|
65
+ "No #{language} version could be read, so llms-#{language}.txt was not written."
73
66
  end
67
+ end
74
68
 
75
- def failure_lines(file)
76
- failure = file.built.failure
77
- return [] unless failure
69
+ def wording_lines
70
+ lines = @files.flat_map { |file| [*failure_lines(file), *unused_lines(file)] }
71
+ lines.empty? ? [] : ["", *lines]
72
+ end
78
73
 
79
- ["The model could not word llms-#{file.language}.txt (#{failure}). It has no summaries, and its " \
80
- "headings are made from the page addresses."]
81
- end
74
+ def failure_lines(file)
75
+ failure = file.built.failure
76
+ return [] unless failure
82
77
 
83
- def unused_lines(file)
84
- notes = file.built.notes
85
- return [] if notes.empty?
78
+ ["The model could not word llms-#{file.language}.txt (#{failure}). It has no summaries, and its " \
79
+ "headings are made from the page addresses."]
80
+ end
86
81
 
87
- ["Left out of the model's answer for #{file.language}:", *notes.first(SHOWN_NOTES).map do |note|
88
- " - #{note}"
89
- end,
90
- *more_line(notes.size - SHOWN_NOTES)]
91
- end
82
+ def unused_lines(file)
83
+ notes = file.built.notes
84
+ return [] if notes.empty?
92
85
 
93
- def unranked_lines
94
- return [] unless @collected.unranked.positive?
86
+ ["Left out of the model's answer for #{file.language}:", *notes.first(SHOWN_NOTES).map do |note|
87
+ " - #{note}"
88
+ end,
89
+ *more_line(notes.size - SHOWN_NOTES)]
90
+ end
95
91
 
96
- ["", "#{@collected.unranked} of these pages have no importance yet, so they come in the order of the " \
97
- "sheet. Run: yuno-proofreader analyze"]
98
- end
92
+ def unranked_lines
93
+ return [] unless @collected.unranked.positive?
99
94
 
100
- def problem_lines
101
- problems = @collected.problems
102
- return [] if problems.empty?
95
+ ["", "#{@collected.unranked} of these pages have no importance yet, so they come in the order of the " \
96
+ "sheet. Run: yuno-proofreader analyze"]
97
+ end
103
98
 
104
- ["", "Left out:", *problems.first(SHOWN_PROBLEMS).map { |problem| " - #{problem}" },
105
- *more_line(problems.size - SHOWN_PROBLEMS)]
106
- end
99
+ def problem_lines
100
+ problems = @collected.problems
101
+ return [] if problems.empty?
107
102
 
108
- def more_line(count) = count.positive? ? [" ... and #{count} more"] : []
103
+ ["", "Left out:", *problems.first(SHOWN_PROBLEMS).map { |problem| " - #{problem}" },
104
+ *more_line(problems.size - SHOWN_PROBLEMS)]
109
105
  end
106
+
107
+ def more_line(count) = count.positive? ? [" ... and #{count} more"] : []
110
108
  end
111
109
  end
112
110
  end