yuno-proofreader 0.1.1 → 0.1.2
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 +7 -0
- data/lib/yuno/proofreader/audit/batch.rb +5 -3
- data/lib/yuno/proofreader/audit/runner.rb +1 -1
- data/lib/yuno/proofreader/audit/schemas.rb +51 -0
- data/lib/yuno/proofreader/llm/client.rb +18 -11
- data/lib/yuno/proofreader/llm/errors.rb +2 -0
- data/lib/yuno/proofreader/llm/provider.rb +1 -1
- data/lib/yuno/proofreader/llm/providers/gemini.rb +7 -5
- data/lib/yuno/proofreader/store/cells.rb +13 -3
- data/lib/yuno/proofreader/version.rb +1 -1
- data/lib/yuno/proofreader.rb +1 -0
- data/proofreader.example.yml +15 -10
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 10d51101947e788caaabb5e519b8996fc7c7e0014724634addd60a70bf4166c1
|
|
4
|
+
data.tar.gz: ebcbd00eb54f2f283c0c528ddf046b67d628bae8de553fe1fe3c096dcb78302b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3d5a551d0d762923d6172cb02bdfb2454d3aec75fb9178994f04f271592b32131263a594b14d44f25882fc30ddbbc2654d13b8fccd4896e77fa456f14ee07ed1
|
|
7
|
+
data.tar.gz: e27afb721465f2003686b9c1c81c57f4fe34c42e0b2daf6eb20d20c0e59c818097d1d2d9f5b2014f0a68212ff41d5c86014341f79eff761f52d7ab3bb67dd772
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.2
|
|
4
|
+
2026/11/19
|
|
5
|
+
|
|
6
|
+
- A page whose model answers can't be parsed is now set aside and retried after the retry period, instead of stopping the whole batch.
|
|
7
|
+
- Model answers are now requested in a fixed JSON schema (used by Gemini), so replies here should be less likely to be unparsable.
|
|
8
|
+
- Pages audited before are no longer treated as never audited when a date cell in the sheet has no date format.
|
|
9
|
+
|
|
3
10
|
## [0.1.1]
|
|
4
11
|
2026/11/14
|
|
5
12
|
|
|
@@ -4,16 +4,16 @@ module Yuno
|
|
|
4
4
|
module Proofreader
|
|
5
5
|
module Audit
|
|
6
6
|
# One page of a batch: what was done and what came of it. status is :audited, :skipped (unchanged, so no model
|
|
7
|
-
# was called) or :failed
|
|
7
|
+
# was called) or :failed
|
|
8
8
|
BatchEntry = Data.define(:pick, :status, :result, :error)
|
|
9
9
|
|
|
10
|
-
# The pages of a batch in the order they were done
|
|
10
|
+
# The pages of a batch in the order they were done
|
|
11
11
|
BatchOutcome = Data.define(:entries, :stopped)
|
|
12
12
|
|
|
13
13
|
# Audits a list of pages one after another. A page that fails for a reason of its own is reported and set aside
|
|
14
14
|
# (marked as audited without a fingerprint, so it comes due again after the retry period and does not hold up
|
|
15
15
|
# the queue), and the batch goes on. A problem that would hit every page (no model available, the sheet not
|
|
16
|
-
# reachable, bad settings) ends the batch
|
|
16
|
+
# reachable, bad settings) ends the batch
|
|
17
17
|
class Batch
|
|
18
18
|
FATAL = [LlmError, StoreError, ConfigError].freeze
|
|
19
19
|
|
|
@@ -45,6 +45,8 @@ module Yuno
|
|
|
45
45
|
result = @runner.run(pick.record.name, dry_run:, force:)
|
|
46
46
|
LogFields.record(@log, result, reason: pick.reason)
|
|
47
47
|
BatchEntry.new(pick:, status: result.status, result:, error: nil)
|
|
48
|
+
rescue Llm::UnusableAnswersError => e
|
|
49
|
+
fail_page(pick, e, dry_run)
|
|
48
50
|
rescue Error => e
|
|
49
51
|
raise if FATAL.any? { |kind| e.is_a?(kind) }
|
|
50
52
|
|
|
@@ -100,7 +100,7 @@ module Yuno
|
|
|
100
100
|
|
|
101
101
|
def ask(role, client, system, user, avoid: [])
|
|
102
102
|
say("Asking the #{role} model (this can take a minute or two)...")
|
|
103
|
-
answer = client.generate(system:, user:, avoid:)
|
|
103
|
+
answer = client.generate(system:, user:, avoid:, schema: Schemas.for_role(role))
|
|
104
104
|
say("The #{role} model answered: #{answer.model}, #{answer.seconds.round} s.")
|
|
105
105
|
Asked.new(answer:, call: Call.new(role:, model: answer.model, seconds: answer.seconds,
|
|
106
106
|
input_tokens: answer.input_tokens, output_tokens: answer.output_tokens,
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Yuno
|
|
4
|
+
module Proofreader
|
|
5
|
+
module Audit
|
|
6
|
+
# What the models are asked to answer with, as JSON Schemas. They only fix the shape, so that an answer is
|
|
7
|
+
# valid JSON. Findings::Finding still decides which items are usable.
|
|
8
|
+
module Schemas
|
|
9
|
+
ISSUE = {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
language: { type: "string" },
|
|
13
|
+
category: { type: "string" },
|
|
14
|
+
effort: { type: "string" },
|
|
15
|
+
original: { type: "string" },
|
|
16
|
+
suggested: { type: "string" },
|
|
17
|
+
reason: { type: "string" }
|
|
18
|
+
},
|
|
19
|
+
required: %w[language category effort original suggested reason]
|
|
20
|
+
}.freeze
|
|
21
|
+
|
|
22
|
+
AUDIT = {
|
|
23
|
+
type: "object",
|
|
24
|
+
properties: {
|
|
25
|
+
steps: {
|
|
26
|
+
type: "array",
|
|
27
|
+
items: {
|
|
28
|
+
type: "object",
|
|
29
|
+
properties: { step: { type: "integer" }, issues: { type: "array", items: ISSUE } },
|
|
30
|
+
required: %w[step issues]
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
required: %w[steps]
|
|
35
|
+
}.freeze
|
|
36
|
+
|
|
37
|
+
REVIEW = {
|
|
38
|
+
type: "object",
|
|
39
|
+
properties: { issues: { type: "array", items: ISSUE } },
|
|
40
|
+
required: %w[issues]
|
|
41
|
+
}.freeze
|
|
42
|
+
|
|
43
|
+
BY_ROLE = { audit: AUDIT, review: REVIEW }.freeze
|
|
44
|
+
|
|
45
|
+
module_function
|
|
46
|
+
|
|
47
|
+
def for_role(role) = BY_ROLE.fetch(role)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -4,9 +4,7 @@ module Yuno
|
|
|
4
4
|
module Proofreader
|
|
5
5
|
module Llm
|
|
6
6
|
# Asks a list of models in turn until one answers with JSON. A model that is over its limit or does not
|
|
7
|
-
# exist is skipped for the rest of the run
|
|
8
|
-
# repeated after a pause. It knows nothing about a particular provider or model. What goes wrong is written
|
|
9
|
-
# to the log as warnings, and each answer, with its tokens, at debug level.
|
|
7
|
+
# exist is skipped for the rest of the run
|
|
10
8
|
class Client
|
|
11
9
|
RETRY_ROUNDS = 3
|
|
12
10
|
RETRY_WAIT = 20
|
|
@@ -36,17 +34,16 @@ module Yuno
|
|
|
36
34
|
# Whether there is a model other than this one, for a second opinion that is independent of the first.
|
|
37
35
|
def independent_of?(model) = @models.any? { |name| name != model }
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
def generate(system:, user:, avoid: [])
|
|
37
|
+
def generate(system:, user:, avoid: [], schema: nil)
|
|
41
38
|
failures = []
|
|
42
39
|
RETRY_ROUNDS.times do |round|
|
|
43
|
-
outcome = round_of(order(avoid), system, user, failures)
|
|
40
|
+
outcome = round_of(order(avoid), system, user, schema, failures)
|
|
44
41
|
return outcome if outcome.is_a?(Answer)
|
|
45
42
|
break unless outcome == :transient && round < RETRY_ROUNDS - 1
|
|
46
43
|
|
|
47
44
|
pause(round)
|
|
48
45
|
end
|
|
49
|
-
raise
|
|
46
|
+
raise exhausted(failures)
|
|
50
47
|
end
|
|
51
48
|
|
|
52
49
|
private
|
|
@@ -63,12 +60,12 @@ module Yuno
|
|
|
63
60
|
end
|
|
64
61
|
|
|
65
62
|
# Tries every model once. Returns the Answer, or :transient when waiting might help, or nil.
|
|
66
|
-
def round_of(models, system, user, failures)
|
|
63
|
+
def round_of(models, system, user, schema, failures)
|
|
67
64
|
transient = false
|
|
68
65
|
models.each do |model|
|
|
69
66
|
next if skipped?(model)
|
|
70
67
|
|
|
71
|
-
result = attempt(model, system, user, failures)
|
|
68
|
+
result = attempt(model, system, user, schema, failures)
|
|
72
69
|
return result if result.is_a?(Answer)
|
|
73
70
|
|
|
74
71
|
transient ||= result == :transient
|
|
@@ -76,9 +73,10 @@ module Yuno
|
|
|
76
73
|
transient ? :transient : nil
|
|
77
74
|
end
|
|
78
75
|
|
|
79
|
-
def attempt(model, system, user, failures)
|
|
76
|
+
def attempt(model, system, user, schema, failures)
|
|
80
77
|
started = @clock.call
|
|
81
|
-
|
|
78
|
+
extra = schema ? { schema: } : {}
|
|
79
|
+
completion = @provider.complete(model:, system:, user:, max_output_tokens: @max_output_tokens, **extra)
|
|
82
80
|
log_answer(answer_from(model, completion, @clock.call - started))
|
|
83
81
|
rescue AnswerError => e
|
|
84
82
|
failures << Failure.new(model:, message: e.message, kind: :answer)
|
|
@@ -134,6 +132,15 @@ module Yuno
|
|
|
134
132
|
|
|
135
133
|
" Run yuno-proofreader models to see which models your key can use, then set models in proofreader.yml."
|
|
136
134
|
end
|
|
135
|
+
|
|
136
|
+
# Every model answered, but none of the answers could be used: that is presumably a problem of the one page,
|
|
137
|
+
# not of the models or the key
|
|
138
|
+
def exhausted(failures)
|
|
139
|
+
message = unavailable_message(failures)
|
|
140
|
+
return UnusableAnswersError.new(message) if failures.any? { |failure| failure.kind == :answer }
|
|
141
|
+
|
|
142
|
+
UnavailableError.new(message)
|
|
143
|
+
end
|
|
137
144
|
end
|
|
138
145
|
end
|
|
139
146
|
end
|
|
@@ -36,7 +36,7 @@ module Yuno
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
# Sends one request. Returns a Completion, or raises ProviderError saying what kind of failure it was.
|
|
39
|
-
def complete(model:, system:, user:, max_output_tokens:)
|
|
39
|
+
def complete(model:, system:, user:, max_output_tokens:, schema: nil)
|
|
40
40
|
raise NotImplementedError, "#{self.class.name} must define #complete"
|
|
41
41
|
end
|
|
42
42
|
|
|
@@ -19,8 +19,8 @@ module Yuno
|
|
|
19
19
|
|
|
20
20
|
def self.api_key_env = "GEMINI_API_KEY"
|
|
21
21
|
|
|
22
|
-
def complete(model:, system:, user:, max_output_tokens:)
|
|
23
|
-
body = JSON.generate(payload(system, user, max_output_tokens))
|
|
22
|
+
def complete(model:, system:, user:, max_output_tokens:, schema: nil)
|
|
23
|
+
body = JSON.generate(payload(model, system, user, max_output_tokens, schema))
|
|
24
24
|
url = "#{BASE}/models/#{normalize(model)}:generateContent"
|
|
25
25
|
response = request(:post, url, headers: auth_headers.merge("Content-Type" => "application/json"), body:)
|
|
26
26
|
raise failure(response) unless response.status == 200
|
|
@@ -46,12 +46,14 @@ module Yuno
|
|
|
46
46
|
|
|
47
47
|
def auth_headers = { "x-goog-api-key" => @api_key }
|
|
48
48
|
|
|
49
|
-
def payload(system, user, max_output_tokens)
|
|
49
|
+
def payload(model, system, user, max_output_tokens, schema)
|
|
50
|
+
config = { responseMimeType: "application/json", maxOutputTokens: max_output_tokens }
|
|
51
|
+
config[:temperature] = 0 if normalize(model).start_with?("gemini-2")
|
|
52
|
+
config[:responseJsonSchema] = schema if schema
|
|
50
53
|
{
|
|
51
54
|
systemInstruction: { parts: [{ text: system }] },
|
|
52
55
|
contents: [{ role: "user", parts: [{ text: user }] }],
|
|
53
|
-
generationConfig:
|
|
54
|
-
maxOutputTokens: max_output_tokens }
|
|
56
|
+
generationConfig: config
|
|
55
57
|
}
|
|
56
58
|
end
|
|
57
59
|
|
|
@@ -7,6 +7,7 @@ module Yuno
|
|
|
7
7
|
module Cells
|
|
8
8
|
EPOCH = Time.utc(1899, 12, 30)
|
|
9
9
|
DATETIME = /\A(\d{4})-(\d{2})-(\d{2})(?:[ T](\d{2}):(\d{2})(?::(\d{2}))?)?\z/
|
|
10
|
+
SERIAL = /\A\d+(?:[.,]\d+)?\z/
|
|
10
11
|
|
|
11
12
|
module_function
|
|
12
13
|
|
|
@@ -31,10 +32,12 @@ module Yuno
|
|
|
31
32
|
# A time as a sheet date: days since 1899-12-30, counted in UTC.
|
|
32
33
|
def serial(time) = (time.getutc - EPOCH) / 86_400.0
|
|
33
34
|
|
|
34
|
-
# Reads "2026-10-24 14:30" (seconds optional, date alone allowed) as UTC
|
|
35
|
+
# Reads "2026-10-24 14:30" (seconds optional, date alone allowed) as UTC, or a sheet date shown as a plain
|
|
36
|
+
# number. Anything else gives nil.
|
|
35
37
|
def parse_time(text)
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
text = text.to_s.strip
|
|
39
|
+
match = DATETIME.match(text)
|
|
40
|
+
return from_serial(text) unless match
|
|
38
41
|
|
|
39
42
|
year, month, day, hour, minute, second = match.captures.map(&:to_i)
|
|
40
43
|
Time.utc(year, month, day, hour, minute, second)
|
|
@@ -42,6 +45,13 @@ module Yuno
|
|
|
42
45
|
nil
|
|
43
46
|
end
|
|
44
47
|
|
|
48
|
+
# A sheet date whose cell has no date format. A decimal comma is read too, as in a German locale.
|
|
49
|
+
def from_serial(text)
|
|
50
|
+
return unless SERIAL.match?(text)
|
|
51
|
+
|
|
52
|
+
EPOCH + (text.tr(",", ".").to_f * 86_400).round
|
|
53
|
+
end
|
|
54
|
+
|
|
45
55
|
def integer(text)
|
|
46
56
|
Integer(text.to_s.strip, 10)
|
|
47
57
|
rescue ArgumentError
|
data/lib/yuno/proofreader.rb
CHANGED
|
@@ -81,6 +81,7 @@ require_relative "proofreader/audit/agenda"
|
|
|
81
81
|
require_relative "proofreader/audit/batch"
|
|
82
82
|
require_relative "proofreader/audit/agenda_report"
|
|
83
83
|
require_relative "proofreader/audit/batch_report"
|
|
84
|
+
require_relative "proofreader/audit/schemas"
|
|
84
85
|
require_relative "proofreader/generate/passage"
|
|
85
86
|
require_relative "proofreader/generate/collector"
|
|
86
87
|
require_relative "proofreader/generate/cache"
|
data/proofreader.example.yml
CHANGED
|
@@ -78,32 +78,35 @@ intentional_differences:
|
|
|
78
78
|
# ---- The AI models ----------------------------------------------------------------------------
|
|
79
79
|
# Everything here is optional. Out of the box nothing needs an account or a key: the tool writes each
|
|
80
80
|
# prompt to tmp/handoff/prompt.md, you paste it into a chat with the model of your choice, save the reply
|
|
81
|
-
# as tmp/handoff/answer.md and press Enter.
|
|
81
|
+
# as tmp/handoff/answer.md and press Enter. `generate llms` uses these settings too.
|
|
82
82
|
#
|
|
83
83
|
# provider Which family of models to use: manual (the default) or gemini.
|
|
84
84
|
# models For gemini: the models to use, best first. When one is overloaded, over its limit or not
|
|
85
85
|
# available to your key, the next one is used. The tool has a built-in list to fall back
|
|
86
86
|
# on, but model names change often, so set your own. `yuno-proofreader models` shows which
|
|
87
87
|
# ones your key can use. The names below are only examples.
|
|
88
|
-
# For manual: only a label, shown to remind you which model to pick in the chat.
|
|
89
|
-
#
|
|
90
|
-
# first audit. Leave it out to use `models`. With only one model there is nothing for the
|
|
91
|
-
# review to be independent of.
|
|
88
|
+
# For manual: only a label, shown to remind you which model to pick in the chat. Write it
|
|
89
|
+
# without spaces, for example fable-5.2
|
|
92
90
|
# review true or false (the default). With true, every audit is followed by an independent second
|
|
93
91
|
# review by a different model, which sends the page to a model a second time and so costs
|
|
94
92
|
# about as much again. `audit --review` turns it on for one run.
|
|
93
|
+
# review_models Optional list for the independent second review, used only when the review is on. It
|
|
94
|
+
# prefers a different model from the first audit. Leave it out to use `models`. With only
|
|
95
|
+
# one model there is nothing for the review to be independent of.
|
|
95
96
|
#
|
|
96
97
|
# provider: gemini
|
|
97
98
|
# models:
|
|
98
99
|
# - gemini-3.8-flash
|
|
99
100
|
# - gemini-3.7-flash
|
|
101
|
+
# review: true
|
|
100
102
|
# review_models:
|
|
101
103
|
# - gemini-3.8-flash-lite
|
|
102
104
|
# - gemini-3.7-flash-lite
|
|
103
105
|
#
|
|
104
|
-
#
|
|
106
|
+
# Or ask a model yourself, in any chat, through tmp/handoff (this is what happens without a provider):
|
|
105
107
|
# provider: manual
|
|
106
|
-
#
|
|
108
|
+
# models:
|
|
109
|
+
# - fable-5.2
|
|
107
110
|
|
|
108
111
|
# ---- Where the results are kept (optional) -------------------------------------------------------
|
|
109
112
|
# Everything here is optional. Out of the box nothing needs an account: the pages, the suggestions and the
|
|
@@ -111,9 +114,11 @@ intentional_differences:
|
|
|
111
114
|
#
|
|
112
115
|
# store csv (the default) or sheets. With sheets the same tabs are kept in a Google Sheet, which needs
|
|
113
116
|
# SPREADSHEET_ID and Google credentials outside this file (see the README, "Connecting to Google").
|
|
114
|
-
# data_dir The folder for the CSV files (pages.csv, suggestions.csv, analysis.csv)
|
|
115
|
-
#
|
|
116
|
-
# it
|
|
117
|
+
# data_dir The folder for the CSV files (pages.csv, suggestions.csv, analysis.csv) and for the files that
|
|
118
|
+
# `generate llms` writes (llms-de.txt and so on, and llms-pages.json), relative to where you run
|
|
119
|
+
# the tool. `~` works. Default: data. Keep it: the CSV files hold the fingerprints and your
|
|
120
|
+
# decisions, and deleting them brings back every suggestion you rejected. With sheets the CSV
|
|
121
|
+
# files are not used, but `generate llms` still writes its files here.
|
|
117
122
|
#
|
|
118
123
|
# store: sheets
|
|
119
124
|
# data_dir: data
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: yuno-proofreader
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sebastian Alsen
|
|
@@ -115,6 +115,7 @@ files:
|
|
|
115
115
|
- lib/yuno/proofreader/audit/prompts/steps.yml
|
|
116
116
|
- lib/yuno/proofreader/audit/report.rb
|
|
117
117
|
- lib/yuno/proofreader/audit/runner.rb
|
|
118
|
+
- lib/yuno/proofreader/audit/schemas.rb
|
|
118
119
|
- lib/yuno/proofreader/audit/steps.rb
|
|
119
120
|
- lib/yuno/proofreader/cli.rb
|
|
120
121
|
- lib/yuno/proofreader/cli/analysis_commands.rb
|