interplane.Get Omega
Read in your language

aien-translate

aien-dev/aien-translate

Brought by drakestapleton

branch main Branches Tags History

aien-translate / AGENTS.md

92 lines · 6254 bytes Raw Blame History Rendered
1# aien-translate (translation server for translate.js, backed by your own model)
2
3> `aien-translate` is a Rust HTTP server that answers the translate.js translation protocol (`/translate.json` and friends) by sending text to an OpenAI-style chat model server, normally AIEN's own inference runtime. Every translation is checked by a guard before a visitor sees it and saved in a SQLite cache. The `scripts/` folder holds Python tools that use a running server to translate a README, a built static website, or a LaTeX paper.
4Shared rules: read https://www.aienos.com/agents/RULES.md first. This file adds what is specific to this repository; where the two differ, this file wins here.
5
6## Scope
7
8- Applies to the whole repository.
9- `src/`: the server. `main.rs` parses flags; `lib.rs` holds the routes and request handling; `engine.rs` talks to the model server; `guard.rs` checks translations; `cache.rs` is the SQLite cache; `langs.rs` is the language list.
10- `tests/protocol.rs`: end-to-end tests against a fake model server. `tests/fixtures/` holds recorded bad model replies.
11- `scripts/translate_readme.py`, `scripts/translate_site.py`, `scripts/translate_latex.py`: clients of a running server.
12- `demo/`: a test page that loads the real translate.js, plus `demo/check.py`. `demo/translate.js` is downloaded, not committed (it is in `.gitignore`).
13- `docs/i18n/README.*.md` are machine translations generated by `scripts/translate_readme.py`. `README.md` (English) is the original. Do not hand-edit the translations; regenerate them.
14- translate.js itself is not in this repository. AIEN keeps a preserved copy at https://github.com/aien-dev/translate; upstream is https://github.com/xnx3/translate.
15
16## Installation
17
18```bash
19git clone https://github.com/aien-dev/aien-translate.git
20cd aien-translate
21cargo build --release
22```
23
24Needs a stable Rust toolchain. SQLite is bundled through `rusqlite`, so no system library is needed. The binary is `target/release/aien-translate`.
25
26Running the server for real needs a model server that offers `GET /v1/models` and `POST /v1/chat/completions` (AIEN's `aien-serve-http` or any OpenAI-style chat server). The tests do not need one.
27
28## Configuration
29
30All configuration is by flag; there is no config file and no environment variable besides `HOME` (used for the default cache path).
31
32```
33--listen loopback address only
34--engine base URL of the model server
35--cache SQLite file for saved translations
36--keep-file names never translated, one per line (default: built-in list)
37--auth-token-file local proxy bearer secret (required for public-site proxying)
38```
39
40`./target/release/aien-translate --help` prints the defaults. The listener refuses non-loopback addresses. Public browser traffic must use a same-origin authenticated and per-visitor-rate-limited reverse proxy; the browser never receives the backend token. See `README.md` for the deployment contract.
41
42## Usage
43
44```bash
45# Unit tests and end-to-end tests against a fake model (no GPU, no network)
46cargo test
47
48# Flag summary and defaults
49./target/release/aien-translate --help
50
51# Run the server (needs a reachable model server)
52./target/release/aien-translate --listen <addr:port> --engine <model-server-url>
53
54# Check a running server
55curl http://<addr:port>/health
56curl -X POST http://<addr:port>/translate.json \
57 -d 'from=english&to=japanese&text=%5B%22Hello%20world%22%5D'
58```
59
60Scripts (all need a running aien-translate; pass its address with `--server URL`):
61
62```bash
63python3 scripts/translate_readme.py [--server URL] [lang ...] # writes docs/i18n/README.<code>.md
64python3 scripts/translate_site.py DIST OUT --langs zh-CN,ja [--server URL] [--base-url URL] # needs beautifulsoup4
65python3 scripts/translate_latex.py paper.tex OUT_DIR --langs zh-CN,ja [--server URL] [--doi DOI] [--dry-run]
66python3 demo/check.py URL # needs Playwright and a served demo/ folder with translate.js
67```
68
69`translate_latex.py --dry-run` prints the pieces the model would see and translates nothing. `translate_readme.py` has no `--help`; unknown arguments are read as language codes.
70
71## Conventions
72
73- The guard is the product. A translation that loses a link, an email address, a backticked code span, a placeholder such as `{name}` or `%s`, a keep-list name, or an inline tag marker, or that is empty or far longer than the source, is rejected and the original text is served. Never loosen a guard rule to make output appear; add a test in `src/guard.rs` or `tests/protocol.rs` for every rule change.
74- When a batch reply cannot be matched to its inputs, the server splits the batch and retries down to single items. Keep that fallback; the fixtures in `tests/fixtures/` are real failure shapes.
75- Model requests go one at a time because the GPU may be shared. Do not add parallel requests to the engine.
76- The language list lives in `src/langs.rs`; the scripts carry their own `LANGS` tables. Update both together.
77- Tests live beside the code in `#[cfg(test)]` modules and in `tests/protocol.rs`. `cargo test` must stay runnable without a GPU or a model server.
78
79## Safety and approvals
80
81- Do not point `--engine` at a shared or production model server without the owner's approval; translation batches compete with its other users.
82- Real translation runs need a GPU-backed model server. Do not start one from this repository.
83- The cache file holds visitors' page text. Never commit it or attach it to an issue or pull request.
84- Machine-translated output (`docs/i18n/`, translated sites or papers) is published as machine translation, never presented as reviewed.
85- Translation admission is bounded in `src/lib.rs` (per-peer IP quota, one active request without queueing, request/body limits). Keep tests for unauthorized, saturated, and positive admission paths. The proxy sees real clients; the backend sees the proxy IP, so native quotas do not replace proxy quotas.
86- Work on a branch and merge through a pull request with the `cargo test` result in its body.
87
88## Further reading
89
90- `README.md`: the three-step setup, endpoint list, guard description and limits.
91- `src/guard.rs`: the exact checks applied to every translation.
92- https://github.com/xnx3/translate: translate.js and its request protocol.