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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/lib/yuno/proofreader/analysis/adjustments.rb +30 -32
- data/lib/yuno/proofreader/analysis/crawler.rb +71 -73
- data/lib/yuno/proofreader/analysis/entries.rb +52 -54
- data/lib/yuno/proofreader/analysis/extractor.rb +162 -164
- data/lib/yuno/proofreader/analysis/graph.rb +86 -88
- data/lib/yuno/proofreader/analysis/judge.rb +80 -82
- data/lib/yuno/proofreader/analysis/judge_prompt.rb +50 -52
- data/lib/yuno/proofreader/analysis/judgments.rb +50 -52
- data/lib/yuno/proofreader/analysis/links.rb +44 -46
- data/lib/yuno/proofreader/analysis/list_order.rb +20 -22
- data/lib/yuno/proofreader/analysis/reasons.rb +44 -43
- data/lib/yuno/proofreader/analysis/report.rb +79 -81
- data/lib/yuno/proofreader/analysis/runner.rb +133 -135
- data/lib/yuno/proofreader/analysis/scorer.rb +97 -99
- data/lib/yuno/proofreader/analysis/settings.rb +65 -67
- data/lib/yuno/proofreader/analysis/signals.rb +77 -79
- data/lib/yuno/proofreader/analysis/structured_data.rb +40 -42
- data/lib/yuno/proofreader/analysis/url_tree.rb +34 -36
- data/lib/yuno/proofreader/analysis/weights.rb +67 -69
- data/lib/yuno/proofreader/audit/agenda.rb +63 -65
- data/lib/yuno/proofreader/audit/agenda_report.rb +44 -46
- data/lib/yuno/proofreader/audit/answers.rb +53 -55
- data/lib/yuno/proofreader/audit/attempt.rb +50 -52
- data/lib/yuno/proofreader/audit/batch.rb +49 -49
- data/lib/yuno/proofreader/audit/batch_report.rb +62 -64
- data/lib/yuno/proofreader/audit/cadence.rb +47 -49
- data/lib/yuno/proofreader/audit/instructions.rb +15 -17
- data/lib/yuno/proofreader/audit/log_fields.rb +16 -18
- data/lib/yuno/proofreader/audit/prompt.rb +118 -120
- data/lib/yuno/proofreader/audit/report.rb +116 -118
- data/lib/yuno/proofreader/audit/runner.rb +150 -152
- data/lib/yuno/proofreader/audit/schemas.rb +49 -0
- data/lib/yuno/proofreader/audit/steps.rb +46 -48
- data/lib/yuno/proofreader/cli/analysis_commands.rb +36 -38
- data/lib/yuno/proofreader/cli/audit_commands.rb +89 -91
- data/lib/yuno/proofreader/cli/command_log.rb +34 -36
- data/lib/yuno/proofreader/cli/flags.rb +33 -35
- data/lib/yuno/proofreader/cli/generate_commands.rb +99 -101
- data/lib/yuno/proofreader/cli/init_command.rb +123 -125
- data/lib/yuno/proofreader/cli/model_commands.rb +35 -37
- data/lib/yuno/proofreader/cli/queue_commands.rb +79 -81
- data/lib/yuno/proofreader/cli/sheet_commands.rb +42 -44
- data/lib/yuno/proofreader/cli.rb +197 -199
- data/lib/yuno/proofreader/config.rb +13 -17
- data/lib/yuno/proofreader/context.rb +45 -50
- data/lib/yuno/proofreader/env_file.rb +52 -56
- data/lib/yuno/proofreader/errors.rb +7 -9
- data/lib/yuno/proofreader/findings/finding.rb +73 -75
- data/lib/yuno/proofreader/findings/matching.rb +21 -23
- data/lib/yuno/proofreader/findings/merger.rb +35 -37
- data/lib/yuno/proofreader/findings/outline.rb +50 -52
- data/lib/yuno/proofreader/findings/plan.rb +14 -16
- data/lib/yuno/proofreader/findings/reconciler.rb +170 -172
- data/lib/yuno/proofreader/findings/source.rb +54 -56
- data/lib/yuno/proofreader/findings/text.rb +24 -26
- data/lib/yuno/proofreader/generate/cache.rb +54 -56
- data/lib/yuno/proofreader/generate/collector.rb +98 -100
- data/lib/yuno/proofreader/generate/describe.rb +18 -20
- data/lib/yuno/proofreader/generate/llm/prompt.rb +50 -52
- data/lib/yuno/proofreader/generate/llm/reader.rb +84 -86
- data/lib/yuno/proofreader/generate/llm/wording.rb +12 -14
- data/lib/yuno/proofreader/generate/llms_builder.rb +36 -38
- data/lib/yuno/proofreader/generate/llms_report.rb +82 -84
- data/lib/yuno/proofreader/generate/llms_txt.rb +99 -101
- data/lib/yuno/proofreader/generate/llms_writer.rb +43 -45
- data/lib/yuno/proofreader/generate/outline.rb +67 -69
- data/lib/yuno/proofreader/generate/passage.rb +41 -43
- data/lib/yuno/proofreader/generate/saved_answer.rb +42 -44
- data/lib/yuno/proofreader/http/client.rb +94 -96
- data/lib/yuno/proofreader/http/net_http_transport.rb +35 -37
- data/lib/yuno/proofreader/http/robots.rb +51 -53
- data/lib/yuno/proofreader/init/ask.rb +45 -47
- data/lib/yuno/proofreader/init/detector.rb +75 -77
- data/lib/yuno/proofreader/init/interview.rb +155 -157
- data/lib/yuno/proofreader/init/parsing.rb +37 -39
- data/lib/yuno/proofreader/init/web.rb +22 -24
- data/lib/yuno/proofreader/llm/client.rb +118 -113
- data/lib/yuno/proofreader/llm/defaults.rb +10 -12
- data/lib/yuno/proofreader/llm/errors.rb +18 -18
- data/lib/yuno/proofreader/llm/factory.rb +34 -36
- data/lib/yuno/proofreader/llm/handoff.rb +86 -88
- data/lib/yuno/proofreader/llm/http_transport.rb +25 -27
- data/lib/yuno/proofreader/llm/json_text.rb +12 -14
- data/lib/yuno/proofreader/llm/provider.rb +49 -51
- data/lib/yuno/proofreader/llm/providers/gemini.rb +111 -111
- data/lib/yuno/proofreader/llm/providers/manual.rb +34 -36
- data/lib/yuno/proofreader/llm/providers.rb +17 -19
- data/lib/yuno/proofreader/llm/types.rb +6 -8
- data/lib/yuno/proofreader/llm/usage.rb +8 -10
- data/lib/yuno/proofreader/log.rb +88 -96
- data/lib/yuno/proofreader/pages/fetcher.rb +53 -55
- data/lib/yuno/proofreader/pages/report.rb +37 -39
- data/lib/yuno/proofreader/pages/snapshot.rb +32 -34
- data/lib/yuno/proofreader/pages/trimmer.rb +23 -25
- data/lib/yuno/proofreader/settings_file.rb +35 -38
- data/lib/yuno/proofreader/site.rb +52 -54
- data/lib/yuno/proofreader/site_reader.rb +122 -124
- data/lib/yuno/proofreader/sitemap/aligner.rb +58 -60
- data/lib/yuno/proofreader/sitemap/importer.rb +19 -21
- data/lib/yuno/proofreader/sitemap/loader.rb +95 -97
- data/lib/yuno/proofreader/sitemap/mismatch.rb +53 -55
- data/lib/yuno/proofreader/sitemap/pairer.rb +171 -173
- data/lib/yuno/proofreader/sitemap/parser.rb +50 -52
- data/lib/yuno/proofreader/sitemap/report.rb +72 -74
- data/lib/yuno/proofreader/store/cells.rb +55 -49
- data/lib/yuno/proofreader/store/gateways/csv.rb +53 -56
- data/lib/yuno/proofreader/store/gateways/google.rb +152 -158
- data/lib/yuno/proofreader/store/memory.rb +60 -64
- data/lib/yuno/proofreader/store/records.rb +18 -20
- data/lib/yuno/proofreader/store/schema.rb +85 -89
- data/lib/yuno/proofreader/store/sheets.rb +132 -145
- data/lib/yuno/proofreader/store/tab_setup.rb +51 -54
- data/lib/yuno/proofreader/version.rb +1 -1
- data/lib/yuno/proofreader.rb +3 -4
- data/proofreader.example.yml +15 -10
- metadata +3 -2
|
@@ -1,113 +1,111 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
module Yuno
|
|
4
|
-
module
|
|
5
|
-
module
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
40
|
+
private
|
|
42
41
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
48
|
-
|
|
46
|
+
list.each { |entry| yield entry if entry.is_a?(Hash) }
|
|
47
|
+
end
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
def skip(note)
|
|
50
|
+
@notes << note
|
|
51
|
+
nil
|
|
52
|
+
end
|
|
54
53
|
|
|
55
|
-
|
|
54
|
+
def clean(value) = Findings::Text.collapse(value.to_s).sub(MARKDOWN_START, "").strip
|
|
56
55
|
|
|
57
|
-
|
|
56
|
+
def whole?(text) = text.match?(SENTENCE_END) && !text.match?(ELLIPSIS)
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
58
|
+
def heading_of(value, section)
|
|
59
|
+
text = clean(value)
|
|
60
|
+
return if text.empty?
|
|
62
61
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
73
|
-
|
|
71
|
+
invented = numbers_not_in(text, section.all_items)
|
|
72
|
+
return text if invented.empty?
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
skip("#{section.id}: the summary has numbers that its pages do not have (#{invented.join(', ')})")
|
|
75
|
+
end
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
85
|
-
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
99
|
-
|
|
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
|
-
|
|
102
|
-
|
|
97
|
+
invented = numbers_not_in(text, [item])
|
|
98
|
+
return text if invented.empty?
|
|
103
99
|
|
|
104
|
-
|
|
105
|
-
|
|
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
|
-
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
def initialize(client: nil, progress: ->(_message) {}, log: Log.null)
|
|
13
|
+
@client = client
|
|
14
|
+
@progress = progress
|
|
15
|
+
@log = log
|
|
16
|
+
end
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
|
|
28
|
+
private
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
def ask(outline, home, language)
|
|
31
|
+
return [nil, Wording::NONE, nil] unless @client && !outline.items.empty?
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
45
|
-
|
|
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
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
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
|
-
|
|
30
|
-
return saved_line if @saved_at
|
|
26
|
+
private
|
|
31
27
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
end
|
|
28
|
+
def read_line
|
|
29
|
+
return saved_line if @saved_at
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
hint = partial? ? " (--all reads every page)" : ""
|
|
32
|
+
"Read the home page and #{pages_taken}#{hint}."
|
|
33
|
+
end
|
|
39
34
|
|
|
40
|
-
|
|
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
|
-
|
|
43
|
-
others = @collected.considered
|
|
44
|
-
return "all #{others} other pages" unless partial?
|
|
39
|
+
def partial? = @collected.pages.size < @collected.considered
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
def pages_taken
|
|
42
|
+
others = @collected.considered
|
|
43
|
+
return "all #{others} other pages" unless partial?
|
|
48
44
|
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
def failure_lines(file)
|
|
75
|
+
failure = file.built.failure
|
|
76
|
+
return [] unless failure
|
|
82
77
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
-
|
|
94
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
end
|
|
92
|
+
def unranked_lines
|
|
93
|
+
return [] unless @collected.unranked.positive?
|
|
99
94
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
def problem_lines
|
|
100
|
+
problems = @collected.problems
|
|
101
|
+
return [] if problems.empty?
|
|
107
102
|
|
|
108
|
-
|
|
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
|