Repository navigation
feat(pipeline): chunk, validate and retry id-keyed translation - #12
Conversation
Language rules and cue numbers live in TOML files, and the prompt that carries them is built in one place. - ko.toml and en.toml follow the design shape: identity, role fragments and the five cue numbers, with the English no-em-dash rule in en.toml rather than the base text. - profile.py validates every file with pydantic, refuses a pair that lacks either file, and refuses a source without source_rules or a target without target_rules so no rule is dropped silently. - prompt.py composes base rules, source fragment, target fragment, context, glossary and previous lines in that fixed order, omitting empty optional sections and capping previous lines at three.
Twenty cues per request, an answer keyed by the string form of the segment id, and a retry that hands the validator's own complaint back to the model. - translate.py chunks the segment list without touching ids, rejects a repeated id, validates every answer against the exact id set with a pydantic model (missing, extra, renumbered, non-canonical, non-string and blank values all named), retries once with that message in the request, then asks for each unresolved id alone. - A line that still cannot be translated keeps its source text and carries an "untranslated" QA flag; the chunk is recorded with its ids and error, and the job continues to the next chunk. - translated.json is rewritten atomically after every chunk, with the chunk index and attempt that produced each line. - openai_client.py speaks the chat-completions shape against a caller-chosen base URL through a ChatClient seam, always asking for json_object; an answer that is not a JSON object is a rejection so the retry carries the parser's complaint, while an unreachable endpoint is a request failure retried without a correction. - 38 tests, no network: a scripted chat client and a stub SDK factory cover the client, and tests/fakes.FakeTranslator covers the chunk, retry and fallback paths.
Master's #8 rewrote the languages lane, so the add/add conflicts in languages/__init__.py, languages/profile.py, pipeline/prompt.py and their tests resolve to master's versions; this branch's earlier language implementation is superseded and the flat en.toml/ko.toml copies are removed. The translation code is kept. openai_client.py now compares the request language against profile.tag instead of the removed profile.code. make check passes.
|
Addressed the test feedback in 89e1222. Deleted (asserted a constant against itself)
Rewritten (behavior, not structure)
Evidence
|
|
Follow-up in 04f2a14. You were right that the dependency was wider than one test. Under
All four now pass One test still asserts twenty: Evidence: |
|
Dropped in 9f99406. The 45-cue test now passes The rule still lives in |
|
Moved in b2df19f.
|
|
Consolidated in 00f4e9d. One handler, one test. The validator raised Where the two exceptions do differ, in
Both retry once and both fall back per id, so the feedback field is the only difference, and On fake answers: they prove an invariant (nothing outside the exact id set can reach
|
|
Trimmed in 25d4fc3: 28 test functions to 20, 292 cases to 281, all green. Cut because nothing a user can observe differs:
Merged rather than cut: extra-id and non-string now one table (both prove a bad answer cannot reach the file); the two SDK failures one table; the two non-object answers one table. Kept because a user hits the difference: every id once per chunk, recovery after one retry, a bad answer never reaching the file, a permanently failed id keeping its source text with the Mutation check: accepting an extra id in the validator fails the suite ( |
|
Fixed in febfa9b. You were right: The three client tests now run the real What the tests now prove:
Mutation proof: stripping No socket opens; |
ab1cb06 to
a144ca2
Compare
|
a144ca2, on the same point.
The SDK stub is gone from the assertions entirely:
|
What
Lane 04, the translate stage: chunk, client and validator. Satisfies XL4.1, XL4.2, XL4.3, XL4.4, XL4.6 and XL4.7.
chunk_segmentsslices segments into chunks of twenty, ids untouched, and refuses a repeated or empty id list (XL4.1).validate_translationchecks one answer against the exact requested id set with a pydantic model: missing, extra, renumbered, non-canonical key, non-string, blank and non-object answers are all rejected with a message a retry can use (XL4.2, XL4.3).translate_segmentsasks once, retries once with that message appended, then asks for each unresolved id alone. An id that still fails keeps its source text, gets theuntranslatedQA flag, the chunk is recorded with its ids and error, and the job continues (XL4.6).translated.jsonis rewritten atomically after every chunk with the chunk index and attempt per line, so a killed job resumes from the file.openai_client.pyis the network edge:ChatClientseam,OpenAIChatClientover the OpenAI SDK at a caller-chosen base URL (a/v1prefix reaches the SDK unchanged and the SDK posts to/v1/chat/completions), alwaysresponse_format: json_object.OpenAITranslatorcomposes the prompt from the language profiles and parses the answer.TranslationUnitis id and text only; no request or answer carries a time (XL4.4).Tests
38 named tests in
tests/pipeline/test_translate.py, no network:FakeTranslatorfor the chunk, retry and fallback paths, a scriptedChatClientfor the prompt and JSON handling, and a stub SDK factory for the base URL.Acceptance:
Base branch
Stacked on
card/languages-prompt(#8) because this stage composes its prompt withprompt.pyand loads rules from the profiles. Retarget tomasterwhen #8 merges.