@llm-translate/cli 1.0.0-next.1
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.
- package/.dockerignore +51 -0
- package/.env.example +33 -0
- package/.github/workflows/docs-pages.yml +57 -0
- package/.github/workflows/release.yml +49 -0
- package/.translaterc.json +44 -0
- package/CLAUDE.md +243 -0
- package/Dockerfile +55 -0
- package/README.md +371 -0
- package/RFC.md +1595 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +4494 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.ts +1152 -0
- package/dist/index.js +3841 -0
- package/dist/index.js.map +1 -0
- package/docker-compose.yml +56 -0
- package/docs/.vitepress/config.ts +161 -0
- package/docs/api/agent.md +262 -0
- package/docs/api/engine.md +274 -0
- package/docs/api/index.md +171 -0
- package/docs/api/providers.md +304 -0
- package/docs/changelog.md +64 -0
- package/docs/cli/dir.md +243 -0
- package/docs/cli/file.md +213 -0
- package/docs/cli/glossary.md +273 -0
- package/docs/cli/index.md +129 -0
- package/docs/cli/init.md +158 -0
- package/docs/cli/serve.md +211 -0
- package/docs/glossary.json +235 -0
- package/docs/guide/chunking.md +272 -0
- package/docs/guide/configuration.md +139 -0
- package/docs/guide/cost-optimization.md +237 -0
- package/docs/guide/docker.md +371 -0
- package/docs/guide/getting-started.md +150 -0
- package/docs/guide/glossary.md +241 -0
- package/docs/guide/index.md +86 -0
- package/docs/guide/ollama.md +515 -0
- package/docs/guide/prompt-caching.md +221 -0
- package/docs/guide/providers.md +232 -0
- package/docs/guide/quality-control.md +206 -0
- package/docs/guide/vitepress-integration.md +265 -0
- package/docs/index.md +63 -0
- package/docs/ja/api/agent.md +262 -0
- package/docs/ja/api/engine.md +274 -0
- package/docs/ja/api/index.md +171 -0
- package/docs/ja/api/providers.md +304 -0
- package/docs/ja/changelog.md +64 -0
- package/docs/ja/cli/dir.md +243 -0
- package/docs/ja/cli/file.md +213 -0
- package/docs/ja/cli/glossary.md +273 -0
- package/docs/ja/cli/index.md +111 -0
- package/docs/ja/cli/init.md +158 -0
- package/docs/ja/guide/chunking.md +271 -0
- package/docs/ja/guide/configuration.md +139 -0
- package/docs/ja/guide/cost-optimization.md +30 -0
- package/docs/ja/guide/getting-started.md +150 -0
- package/docs/ja/guide/glossary.md +214 -0
- package/docs/ja/guide/index.md +32 -0
- package/docs/ja/guide/ollama.md +410 -0
- package/docs/ja/guide/prompt-caching.md +221 -0
- package/docs/ja/guide/providers.md +232 -0
- package/docs/ja/guide/quality-control.md +137 -0
- package/docs/ja/guide/vitepress-integration.md +265 -0
- package/docs/ja/index.md +58 -0
- package/docs/ko/api/agent.md +262 -0
- package/docs/ko/api/engine.md +274 -0
- package/docs/ko/api/index.md +171 -0
- package/docs/ko/api/providers.md +304 -0
- package/docs/ko/changelog.md +64 -0
- package/docs/ko/cli/dir.md +243 -0
- package/docs/ko/cli/file.md +213 -0
- package/docs/ko/cli/glossary.md +273 -0
- package/docs/ko/cli/index.md +111 -0
- package/docs/ko/cli/init.md +158 -0
- package/docs/ko/guide/chunking.md +271 -0
- package/docs/ko/guide/configuration.md +139 -0
- package/docs/ko/guide/cost-optimization.md +30 -0
- package/docs/ko/guide/getting-started.md +150 -0
- package/docs/ko/guide/glossary.md +214 -0
- package/docs/ko/guide/index.md +32 -0
- package/docs/ko/guide/ollama.md +410 -0
- package/docs/ko/guide/prompt-caching.md +221 -0
- package/docs/ko/guide/providers.md +232 -0
- package/docs/ko/guide/quality-control.md +137 -0
- package/docs/ko/guide/vitepress-integration.md +265 -0
- package/docs/ko/index.md +58 -0
- package/docs/zh/api/agent.md +262 -0
- package/docs/zh/api/engine.md +274 -0
- package/docs/zh/api/index.md +171 -0
- package/docs/zh/api/providers.md +304 -0
- package/docs/zh/changelog.md +64 -0
- package/docs/zh/cli/dir.md +243 -0
- package/docs/zh/cli/file.md +213 -0
- package/docs/zh/cli/glossary.md +273 -0
- package/docs/zh/cli/index.md +111 -0
- package/docs/zh/cli/init.md +158 -0
- package/docs/zh/guide/chunking.md +271 -0
- package/docs/zh/guide/configuration.md +139 -0
- package/docs/zh/guide/cost-optimization.md +30 -0
- package/docs/zh/guide/getting-started.md +150 -0
- package/docs/zh/guide/glossary.md +214 -0
- package/docs/zh/guide/index.md +32 -0
- package/docs/zh/guide/ollama.md +410 -0
- package/docs/zh/guide/prompt-caching.md +221 -0
- package/docs/zh/guide/providers.md +232 -0
- package/docs/zh/guide/quality-control.md +137 -0
- package/docs/zh/guide/vitepress-integration.md +265 -0
- package/docs/zh/index.md +58 -0
- package/package.json +91 -0
- package/release.config.mjs +15 -0
- package/schemas/glossary.schema.json +110 -0
- package/src/cli/commands/dir.ts +469 -0
- package/src/cli/commands/file.ts +291 -0
- package/src/cli/commands/glossary.ts +221 -0
- package/src/cli/commands/init.ts +68 -0
- package/src/cli/commands/serve.ts +60 -0
- package/src/cli/index.ts +64 -0
- package/src/cli/options.ts +59 -0
- package/src/core/agent.ts +1119 -0
- package/src/core/chunker.ts +391 -0
- package/src/core/engine.ts +634 -0
- package/src/errors.ts +188 -0
- package/src/index.ts +147 -0
- package/src/integrations/vitepress.ts +549 -0
- package/src/parsers/markdown.ts +383 -0
- package/src/providers/claude.ts +259 -0
- package/src/providers/interface.ts +109 -0
- package/src/providers/ollama.ts +379 -0
- package/src/providers/openai.ts +308 -0
- package/src/providers/registry.ts +153 -0
- package/src/server/index.ts +152 -0
- package/src/server/middleware/auth.ts +93 -0
- package/src/server/middleware/logger.ts +90 -0
- package/src/server/routes/health.ts +84 -0
- package/src/server/routes/translate.ts +210 -0
- package/src/server/types.ts +138 -0
- package/src/services/cache.ts +899 -0
- package/src/services/config.ts +217 -0
- package/src/services/glossary.ts +247 -0
- package/src/types/analysis.ts +164 -0
- package/src/types/index.ts +265 -0
- package/src/types/modes.ts +121 -0
- package/src/types/mqm.ts +157 -0
- package/src/utils/logger.ts +141 -0
- package/src/utils/tokens.ts +116 -0
- package/tests/fixtures/glossaries/ml-glossary.json +53 -0
- package/tests/fixtures/input/lynq-installation.ko.md +350 -0
- package/tests/fixtures/input/lynq-installation.md +350 -0
- package/tests/fixtures/input/simple.ko.md +27 -0
- package/tests/fixtures/input/simple.md +27 -0
- package/tests/unit/chunker.test.ts +229 -0
- package/tests/unit/glossary.test.ts +146 -0
- package/tests/unit/markdown.test.ts +205 -0
- package/tests/unit/tokens.test.ts +81 -0
- package/tsconfig.json +28 -0
- package/tsup.config.ts +34 -0
- package/vitest.config.ts +16 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
# Chunking Strategy
|
|
2
|
+
|
|
3
|
+
::: info Translations
|
|
4
|
+
All non-English documentation is automatically translated using Claude Sonnet 4.
|
|
5
|
+
:::
|
|
6
|
+
|
|
7
|
+
Large documents are split into chunks for translation. Understanding chunking helps optimize quality and cost.
|
|
8
|
+
|
|
9
|
+
## Why Chunking?
|
|
10
|
+
|
|
11
|
+
LLMs have context limits and perform better on focused content:
|
|
12
|
+
|
|
13
|
+
| Reason | Description |
|
|
14
|
+
|--------|-------------|
|
|
15
|
+
| **Context limits** | Models have maximum input sizes |
|
|
16
|
+
| **Quality** | Smaller chunks get more focused attention |
|
|
17
|
+
| **Cost** | Allows caching of repeated content |
|
|
18
|
+
| **Progress** | Enables progress tracking and resumption |
|
|
19
|
+
|
|
20
|
+
## Default Configuration
|
|
21
|
+
|
|
22
|
+
```json
|
|
23
|
+
{
|
|
24
|
+
"chunking": {
|
|
25
|
+
"maxTokens": 1024,
|
|
26
|
+
"overlapTokens": 150
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Chunk Size Options
|
|
32
|
+
|
|
33
|
+
### maxTokens
|
|
34
|
+
|
|
35
|
+
Maximum tokens per chunk (excluding prompt overhead).
|
|
36
|
+
|
|
37
|
+
| Size | Best For | Trade-off |
|
|
38
|
+
|------|----------|-----------|
|
|
39
|
+
| 512 | High quality requirements | More API calls |
|
|
40
|
+
| **1024** | General use (default) | Balanced |
|
|
41
|
+
| 2048 | Cost optimization | May reduce quality |
|
|
42
|
+
|
|
43
|
+
### overlapTokens
|
|
44
|
+
|
|
45
|
+
Context from previous chunk ensures continuity across boundaries.
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
Chunk 1: [Content A ]
|
|
49
|
+
Chunk 2: [overlap][Content B ]
|
|
50
|
+
Chunk 3: [overlap][Content C ]
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
::: tip Recommended Overlap
|
|
54
|
+
Use 10-15% of your `maxTokens` value. For 1024 tokens, 100-150 overlap tokens work well.
|
|
55
|
+
:::
|
|
56
|
+
|
|
57
|
+
## Markdown-Aware Chunking
|
|
58
|
+
|
|
59
|
+
llm-translate uses AST-based chunking that respects document structure.
|
|
60
|
+
|
|
61
|
+
### Preserved Boundaries
|
|
62
|
+
|
|
63
|
+
The chunker never splits these elements:
|
|
64
|
+
|
|
65
|
+
| Element | Behavior |
|
|
66
|
+
|---------|----------|
|
|
67
|
+
| Headers | Section boundaries preserved |
|
|
68
|
+
| Code blocks | Always kept intact |
|
|
69
|
+
| Lists | Items grouped when possible |
|
|
70
|
+
| Tables | Never split across chunks |
|
|
71
|
+
| Paragraphs | Split at natural boundaries |
|
|
72
|
+
|
|
73
|
+
### Example
|
|
74
|
+
|
|
75
|
+
::: details Click to see chunking example
|
|
76
|
+
|
|
77
|
+
**Input document:**
|
|
78
|
+
|
|
79
|
+
```markdown
|
|
80
|
+
# Introduction
|
|
81
|
+
|
|
82
|
+
This is the introduction paragraph that explains
|
|
83
|
+
the purpose of the document.
|
|
84
|
+
|
|
85
|
+
## Getting Started
|
|
86
|
+
|
|
87
|
+
### Prerequisites
|
|
88
|
+
|
|
89
|
+
- Node.js 20+
|
|
90
|
+
- npm or yarn
|
|
91
|
+
|
|
92
|
+
### Installation
|
|
93
|
+
|
|
94
|
+
npm install @llm-translate/cli
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Result:**
|
|
98
|
+
|
|
99
|
+
```
|
|
100
|
+
Chunk 1: # Introduction + paragraph
|
|
101
|
+
Chunk 2: ## Getting Started + ### Prerequisites + list
|
|
102
|
+
Chunk 3: ### Installation + code block
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
:::
|
|
106
|
+
|
|
107
|
+
## Configuration
|
|
108
|
+
|
|
109
|
+
::: code-group
|
|
110
|
+
|
|
111
|
+
```bash [CLI]
|
|
112
|
+
llm-translate file doc.md --target ko --chunk-size 2048
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
```json [.translaterc.json]
|
|
116
|
+
{
|
|
117
|
+
"chunking": {
|
|
118
|
+
"maxTokens": 2048,
|
|
119
|
+
"overlapTokens": 200,
|
|
120
|
+
"preservePatterns": [
|
|
121
|
+
"```[\\s\\S]*?```",
|
|
122
|
+
"\\|[^\\n]+\\|"
|
|
123
|
+
]
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
```typescript [Programmatic]
|
|
129
|
+
import { chunkContent } from '@llm-translate/cli';
|
|
130
|
+
|
|
131
|
+
const chunks = chunkContent(content, {
|
|
132
|
+
maxTokens: 1024,
|
|
133
|
+
overlapTokens: 150,
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
:::
|
|
138
|
+
|
|
139
|
+
## Optimization Presets
|
|
140
|
+
|
|
141
|
+
Choose based on your priority:
|
|
142
|
+
|
|
143
|
+
::: code-group
|
|
144
|
+
|
|
145
|
+
```json [Quality Focus]
|
|
146
|
+
{
|
|
147
|
+
"chunking": {
|
|
148
|
+
"maxTokens": 512,
|
|
149
|
+
"overlapTokens": 100
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
```json [Cost Focus]
|
|
155
|
+
{
|
|
156
|
+
"chunking": {
|
|
157
|
+
"maxTokens": 2048,
|
|
158
|
+
"overlapTokens": 50
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
```json [Long Documents]
|
|
164
|
+
{
|
|
165
|
+
"chunking": {
|
|
166
|
+
"maxTokens": 1500,
|
|
167
|
+
"overlapTokens": 150
|
|
168
|
+
},
|
|
169
|
+
"translation": {
|
|
170
|
+
"maxIterations": 3
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
:::
|
|
176
|
+
|
|
177
|
+
::: info When to use each preset
|
|
178
|
+
- **Quality Focus**: Technical documentation, legal content
|
|
179
|
+
- **Cost Focus**: Blog posts, general content
|
|
180
|
+
- **Long Documents**: Books, comprehensive guides
|
|
181
|
+
:::
|
|
182
|
+
|
|
183
|
+
## Content Preservation
|
|
184
|
+
|
|
185
|
+
### What Gets Protected
|
|
186
|
+
|
|
187
|
+
llm-translate automatically protects certain content from translation:
|
|
188
|
+
|
|
189
|
+
| Content Type | Example | Behavior |
|
|
190
|
+
|--------------|---------|----------|
|
|
191
|
+
| Code blocks | ` ```js ... ``` ` | Never translated |
|
|
192
|
+
| Inline code | `` `variable` `` | Preserved |
|
|
193
|
+
| URLs | `https://...` | Preserved |
|
|
194
|
+
| File paths | `./path/to/file` | Preserved |
|
|
195
|
+
|
|
196
|
+
### Link Handling
|
|
197
|
+
|
|
198
|
+
Link URLs are preserved, but link text is translated:
|
|
199
|
+
|
|
200
|
+
```markdown
|
|
201
|
+
[Getting Started](./getting-started.md)
|
|
202
|
+
↓
|
|
203
|
+
[시작하기](./getting-started.md)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Debugging
|
|
207
|
+
|
|
208
|
+
### Preview Chunks
|
|
209
|
+
|
|
210
|
+
Use `--dry-run` to see how your document will be chunked:
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
llm-translate file doc.md --target ko --dry-run --verbose
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
Output:
|
|
217
|
+
```
|
|
218
|
+
Document Analysis:
|
|
219
|
+
Total tokens: ~5,200
|
|
220
|
+
Chunks: 6
|
|
221
|
+
Average chunk size: ~867 tokens
|
|
222
|
+
|
|
223
|
+
Chunk breakdown:
|
|
224
|
+
[1] Lines 1-45 (Introduction) - 823 tokens
|
|
225
|
+
[2] Lines 46-89 (Getting Started) - 912 tokens
|
|
226
|
+
[3] Lines 90-134 (Configuration) - 878 tokens
|
|
227
|
+
...
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Programmatic Inspection
|
|
231
|
+
|
|
232
|
+
```typescript
|
|
233
|
+
import { chunkContent, getChunkStats } from '@llm-translate/cli';
|
|
234
|
+
|
|
235
|
+
const chunks = chunkContent(content, { maxTokens: 1024 });
|
|
236
|
+
const stats = getChunkStats(chunks);
|
|
237
|
+
|
|
238
|
+
console.log(`Total chunks: ${stats.count}`);
|
|
239
|
+
console.log(`Average size: ${stats.avgTokens} tokens`);
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Troubleshooting
|
|
243
|
+
|
|
244
|
+
::: warning Chunks Too Small
|
|
245
|
+
**Symptom**: Many small chunks, excessive API calls
|
|
246
|
+
|
|
247
|
+
**Solution**: Increase `maxTokens`
|
|
248
|
+
```json
|
|
249
|
+
{ "chunking": { "maxTokens": 2048 } }
|
|
250
|
+
```
|
|
251
|
+
:::
|
|
252
|
+
|
|
253
|
+
::: warning Lost Context Between Chunks
|
|
254
|
+
**Symptom**: Inconsistent terminology across sections
|
|
255
|
+
|
|
256
|
+
**Solution**: Increase overlap or use glossary
|
|
257
|
+
```json
|
|
258
|
+
{ "chunking": { "overlapTokens": 300 } }
|
|
259
|
+
```
|
|
260
|
+
:::
|
|
261
|
+
|
|
262
|
+
::: danger Code Blocks Being Split
|
|
263
|
+
**Symptom**: Syntax errors in output
|
|
264
|
+
|
|
265
|
+
**Cause**: This should never happen. If it does, please [report an issue](https://github.com/selenehyun/llm-translate/issues).
|
|
266
|
+
:::
|
|
267
|
+
|
|
268
|
+
::: warning Tables Being Mangled
|
|
269
|
+
**Symptom**: Broken table formatting
|
|
270
|
+
|
|
271
|
+
**Solution**: Tables should be kept intact automatically. For very large tables (100+ rows), consider splitting them manually.
|
|
272
|
+
:::
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Configuration
|
|
2
|
+
|
|
3
|
+
::: info Translations
|
|
4
|
+
All non-English documentation is automatically translated using Claude Sonnet 4.
|
|
5
|
+
:::
|
|
6
|
+
|
|
7
|
+
llm-translate uses a layered configuration system. Settings are applied in this order (later overrides earlier):
|
|
8
|
+
|
|
9
|
+
1. Built-in defaults
|
|
10
|
+
2. Configuration file (`.translaterc.json`)
|
|
11
|
+
3. Environment variables
|
|
12
|
+
4. CLI arguments
|
|
13
|
+
|
|
14
|
+
## Configuration File
|
|
15
|
+
|
|
16
|
+
Create `.translaterc.json` in your project root:
|
|
17
|
+
|
|
18
|
+
```json
|
|
19
|
+
{
|
|
20
|
+
"provider": {
|
|
21
|
+
"name": "claude",
|
|
22
|
+
"model": "claude-haiku-4-5-20251001",
|
|
23
|
+
"apiKey": null
|
|
24
|
+
},
|
|
25
|
+
"translation": {
|
|
26
|
+
"qualityThreshold": 85,
|
|
27
|
+
"maxIterations": 4,
|
|
28
|
+
"preserveFormatting": true
|
|
29
|
+
},
|
|
30
|
+
"chunking": {
|
|
31
|
+
"maxTokens": 1024,
|
|
32
|
+
"overlapTokens": 150
|
|
33
|
+
},
|
|
34
|
+
"paths": {
|
|
35
|
+
"glossary": "./glossary.json",
|
|
36
|
+
"cache": "./.translate-cache"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Provider Settings
|
|
42
|
+
|
|
43
|
+
| Option | Type | Default | Description |
|
|
44
|
+
|--------|------|---------|-------------|
|
|
45
|
+
| `name` | string | `"claude"` | Provider name: `claude`, `openai`, `ollama` |
|
|
46
|
+
| `model` | string | varies | Model identifier |
|
|
47
|
+
| `apiKey` | string | null | API key (prefer env var) |
|
|
48
|
+
| `baseUrl` | string | null | Custom API endpoint |
|
|
49
|
+
|
|
50
|
+
### Translation Settings
|
|
51
|
+
|
|
52
|
+
| Option | Type | Default | Description |
|
|
53
|
+
|--------|------|---------|-------------|
|
|
54
|
+
| `qualityThreshold` | number | `85` | Minimum quality score (0-100) |
|
|
55
|
+
| `maxIterations` | number | `4` | Maximum refinement iterations |
|
|
56
|
+
| `preserveFormatting` | boolean | `true` | Preserve markdown/HTML structure |
|
|
57
|
+
|
|
58
|
+
### Chunking Settings
|
|
59
|
+
|
|
60
|
+
| Option | Type | Default | Description |
|
|
61
|
+
|--------|------|---------|-------------|
|
|
62
|
+
| `maxTokens` | number | `1024` | Maximum tokens per chunk |
|
|
63
|
+
| `overlapTokens` | number | `150` | Context overlap between chunks |
|
|
64
|
+
|
|
65
|
+
### Path Settings
|
|
66
|
+
|
|
67
|
+
| Option | Type | Default | Description |
|
|
68
|
+
|--------|------|---------|-------------|
|
|
69
|
+
| `glossary` | string | null | Path to glossary file |
|
|
70
|
+
| `cache` | string | null | Path to translation cache |
|
|
71
|
+
|
|
72
|
+
## Environment Variables
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
# API Keys
|
|
76
|
+
ANTHROPIC_API_KEY=sk-ant-xxxxx
|
|
77
|
+
OPENAI_API_KEY=sk-xxxxx
|
|
78
|
+
OLLAMA_BASE_URL=http://localhost:11434
|
|
79
|
+
|
|
80
|
+
# Default Settings
|
|
81
|
+
LLM_TRANSLATE_PROVIDER=claude
|
|
82
|
+
LLM_TRANSLATE_MODEL=claude-haiku-4-5-20251001
|
|
83
|
+
LLM_TRANSLATE_QUALITY_THRESHOLD=85
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## CLI Override Examples
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Override provider
|
|
90
|
+
llm-translate file doc.md -o doc.ko.md --target ko --provider openai
|
|
91
|
+
|
|
92
|
+
# Override model
|
|
93
|
+
llm-translate file doc.md -o doc.ko.md --target ko --model claude-sonnet-4-5-20250929
|
|
94
|
+
|
|
95
|
+
# Override quality threshold
|
|
96
|
+
llm-translate file doc.md -o doc.ko.md --target ko --quality 90
|
|
97
|
+
|
|
98
|
+
# Override max iterations
|
|
99
|
+
llm-translate file doc.md -o doc.ko.md --target ko --max-iterations 6
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Per-Project Configuration
|
|
103
|
+
|
|
104
|
+
For monorepos or multi-project setups, place `.translaterc.json` in each project directory:
|
|
105
|
+
|
|
106
|
+
```
|
|
107
|
+
my-monorepo/
|
|
108
|
+
├── packages/
|
|
109
|
+
│ ├── frontend/
|
|
110
|
+
│ │ ├── .translaterc.json # Frontend-specific terms
|
|
111
|
+
│ │ └── docs/
|
|
112
|
+
│ └── backend/
|
|
113
|
+
│ ├── .translaterc.json # Backend-specific terms
|
|
114
|
+
│ └── docs/
|
|
115
|
+
└── .translaterc.json # Shared defaults
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
llm-translate searches for config files from the current directory upward.
|
|
119
|
+
|
|
120
|
+
## Model Selection Guide
|
|
121
|
+
|
|
122
|
+
| Model | Speed | Quality | Cost | Best For |
|
|
123
|
+
|-------|-------|---------|------|----------|
|
|
124
|
+
| `claude-haiku-4-5-20251001` | Fast | Good | Low | General docs, high volume |
|
|
125
|
+
| `claude-sonnet-4-5-20250929` | Medium | Excellent | Medium | Technical docs, quality-critical |
|
|
126
|
+
| `claude-opus-4-5-20251101` | Slow | Best | High | Complex content, nuanced text |
|
|
127
|
+
| `gpt-4o-mini` | Fast | Good | Low | Alternative to Haiku |
|
|
128
|
+
| `gpt-4o` | Medium | Excellent | Medium | Alternative to Sonnet |
|
|
129
|
+
|
|
130
|
+
## Quality Threshold Guidelines
|
|
131
|
+
|
|
132
|
+
| Threshold | Use Case |
|
|
133
|
+
|-----------|----------|
|
|
134
|
+
| 70-75 | Draft translations, internal docs |
|
|
135
|
+
| 80-85 | Standard documentation (default) |
|
|
136
|
+
| 90-95 | Public-facing, marketing content |
|
|
137
|
+
| 95+ | Legal, medical, regulated content |
|
|
138
|
+
|
|
139
|
+
Higher thresholds require more iterations and cost more.
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
# Cost Optimization
|
|
2
|
+
|
|
3
|
+
::: info Translations
|
|
4
|
+
All non-English documentation is automatically translated using Claude Sonnet 4.
|
|
5
|
+
:::
|
|
6
|
+
|
|
7
|
+
This guide covers strategies to minimize API costs while maintaining translation quality.
|
|
8
|
+
|
|
9
|
+
## Cost Structure
|
|
10
|
+
|
|
11
|
+
### Token Pricing (as of 2025)
|
|
12
|
+
|
|
13
|
+
| Model | Input (1K) | Output (1K) | Cache Read | Cache Write |
|
|
14
|
+
|-------|-----------|-------------|------------|-------------|
|
|
15
|
+
| Claude Haiku 4.5 | $0.001 | $0.005 | $0.0001 | $0.00125 |
|
|
16
|
+
| Claude Sonnet 4.5 | $0.003 | $0.015 | $0.0003 | $0.00375 |
|
|
17
|
+
| Claude Opus 4.5 | $0.015 | $0.075 | $0.0015 | $0.01875 |
|
|
18
|
+
| GPT-4o-mini | $0.00015 | $0.0006 | Auto | Auto |
|
|
19
|
+
| GPT-4o | $0.0025 | $0.01 | Auto | Auto |
|
|
20
|
+
|
|
21
|
+
### Cost Factors
|
|
22
|
+
|
|
23
|
+
1. **Input tokens**: Source text + glossary + prompts
|
|
24
|
+
2. **Output tokens**: Translated text
|
|
25
|
+
3. **Iterations**: Quality refinement cycles (multiply by iterations)
|
|
26
|
+
4. **Cache efficiency**: Savings from prompt caching
|
|
27
|
+
|
|
28
|
+
## Optimization Strategies
|
|
29
|
+
|
|
30
|
+
### 1. Choose the Right Model
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
# Most cost-effective for standard docs
|
|
34
|
+
llm-translate file doc.md --model claude-haiku-4-5-20251001
|
|
35
|
+
|
|
36
|
+
# Better quality when needed
|
|
37
|
+
llm-translate file important.md --model claude-sonnet-4-5-20250929
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
**Model selection guide:**
|
|
41
|
+
|
|
42
|
+
| Content Type | Recommended Model |
|
|
43
|
+
|--------------|-------------------|
|
|
44
|
+
| README, guides | Haiku |
|
|
45
|
+
| API reference | Haiku |
|
|
46
|
+
| User-facing docs | Sonnet |
|
|
47
|
+
| Marketing content | Sonnet/Opus |
|
|
48
|
+
| Legal/compliance | Opus |
|
|
49
|
+
|
|
50
|
+
### 2. Optimize Quality Settings
|
|
51
|
+
|
|
52
|
+
Lower threshold = fewer iterations = lower cost
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
# Draft quality (faster, cheaper)
|
|
56
|
+
llm-translate file doc.md --quality 70 --max-iterations 2
|
|
57
|
+
|
|
58
|
+
# Standard quality
|
|
59
|
+
llm-translate file doc.md --quality 85 --max-iterations 4
|
|
60
|
+
|
|
61
|
+
# High quality (slower, more expensive)
|
|
62
|
+
llm-translate file doc.md --quality 95 --max-iterations 6
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Cost impact:**
|
|
66
|
+
|
|
67
|
+
| Setting | Avg Iterations | Relative Cost |
|
|
68
|
+
|---------|---------------|---------------|
|
|
69
|
+
| quality=70, iter=2 | 1.5 | 0.5x |
|
|
70
|
+
| quality=85, iter=4 | 2.5 | 1.0x |
|
|
71
|
+
| quality=95, iter=6 | 4.0 | 1.6x |
|
|
72
|
+
|
|
73
|
+
### 3. Maximize Prompt Caching
|
|
74
|
+
|
|
75
|
+
Enable caching and process files in batches:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Process all files together to share cache
|
|
79
|
+
llm-translate dir ./docs ./docs-ko --target ko
|
|
80
|
+
|
|
81
|
+
# Not: Process one file at a time
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
See [Prompt Caching](./prompt-caching) for details.
|
|
85
|
+
|
|
86
|
+
### 4. Optimize Glossary Size
|
|
87
|
+
|
|
88
|
+
Large glossaries increase costs. Keep only necessary terms:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# Check glossary token count
|
|
92
|
+
llm-translate glossary stats --glossary glossary.json
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Best practices:**
|
|
96
|
+
- Remove unused terms regularly
|
|
97
|
+
- Use `doNotTranslate` sparingly
|
|
98
|
+
- Split large glossaries by domain
|
|
99
|
+
|
|
100
|
+
### 5. Chunk Size Optimization
|
|
101
|
+
|
|
102
|
+
Larger chunks = fewer API calls = lower overhead
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"chunking": {
|
|
107
|
+
"maxTokens": 2048,
|
|
108
|
+
"overlapTokens": 200
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Trade-offs:**
|
|
114
|
+
|
|
115
|
+
| Chunk Size | API Calls | Quality | Cost |
|
|
116
|
+
|------------|-----------|---------|------|
|
|
117
|
+
| 512 tokens | Many | Higher | Higher |
|
|
118
|
+
| 1024 tokens | Medium | Good | Medium |
|
|
119
|
+
| 2048 tokens | Fewer | Acceptable | Lower |
|
|
120
|
+
|
|
121
|
+
### 6. Use Translation Cache
|
|
122
|
+
|
|
123
|
+
Cache translated chunks to avoid re-translating:
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
{
|
|
127
|
+
"paths": {
|
|
128
|
+
"cache": "./.translate-cache"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Benefits:
|
|
134
|
+
- Skip unchanged content on re-runs
|
|
135
|
+
- Reduce costs for incremental updates
|
|
136
|
+
- Faster subsequent translations
|
|
137
|
+
|
|
138
|
+
## Cost Estimation
|
|
139
|
+
|
|
140
|
+
### Before Translation
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
llm-translate estimate doc.md --target ko --glossary glossary.json
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Output:
|
|
147
|
+
```
|
|
148
|
+
Estimated costs for doc.md:
|
|
149
|
+
Chunks: 15
|
|
150
|
+
Input tokens: ~18,000
|
|
151
|
+
Output tokens: ~20,000 (estimated)
|
|
152
|
+
Iterations: 2-3 (estimated)
|
|
153
|
+
|
|
154
|
+
Model: claude-haiku-4-5-20251001
|
|
155
|
+
Without caching: $0.12 - $0.18
|
|
156
|
+
With caching: $0.05 - $0.08 (55-60% savings)
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### After Translation
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
llm-translate file doc.md -o doc.ko.md --target ko --verbose
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Output:
|
|
166
|
+
```
|
|
167
|
+
✓ Translation complete
|
|
168
|
+
Tokens: 18,234 input / 21,456 output
|
|
169
|
+
Cache: 12,000 read / 3,000 written
|
|
170
|
+
Cost: $0.067 (estimated)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Batch Processing Economics
|
|
174
|
+
|
|
175
|
+
### Single File vs Batch
|
|
176
|
+
|
|
177
|
+
| Approach | Cache Efficiency | Total Cost |
|
|
178
|
+
|----------|-----------------|------------|
|
|
179
|
+
| 10 files sequentially | 0% | $1.00 |
|
|
180
|
+
| 10 files with caching | 80% | $0.35 |
|
|
181
|
+
| Batch directory | 85% | $0.30 |
|
|
182
|
+
|
|
183
|
+
### Optimal Batch Size
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
# Process in batches of 20-50 files for best cache utilization
|
|
187
|
+
llm-translate dir ./docs ./docs-ko --target ko --concurrency 5
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Cost Monitoring
|
|
191
|
+
|
|
192
|
+
### Per-Project Tracking
|
|
193
|
+
|
|
194
|
+
Create a cost log:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
llm-translate file doc.md --cost-log ./costs.json
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Cost Alerts
|
|
201
|
+
|
|
202
|
+
Set budget limits:
|
|
203
|
+
|
|
204
|
+
```json
|
|
205
|
+
{
|
|
206
|
+
"budget": {
|
|
207
|
+
"maxCostPerFile": 0.50,
|
|
208
|
+
"maxCostPerRun": 10.00,
|
|
209
|
+
"warnAt": 0.80
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Cost Comparison by Language
|
|
215
|
+
|
|
216
|
+
Output varies by target language:
|
|
217
|
+
|
|
218
|
+
| Target | Relative Output Tokens |
|
|
219
|
+
|--------|----------------------|
|
|
220
|
+
| Korean | 0.9-1.1x source |
|
|
221
|
+
| Japanese | 0.8-1.0x source |
|
|
222
|
+
| Chinese | 0.7-0.9x source |
|
|
223
|
+
| German | 1.1-1.3x source |
|
|
224
|
+
| Spanish | 1.1-1.2x source |
|
|
225
|
+
|
|
226
|
+
Factor this into cost estimates.
|
|
227
|
+
|
|
228
|
+
## Summary: Quick Cost Reduction Checklist
|
|
229
|
+
|
|
230
|
+
- [ ] Use Haiku for standard documentation
|
|
231
|
+
- [ ] Set quality threshold appropriately (not higher than needed)
|
|
232
|
+
- [ ] Enable and maximize prompt caching
|
|
233
|
+
- [ ] Process files in batches
|
|
234
|
+
- [ ] Keep glossary lean
|
|
235
|
+
- [ ] Use translation cache for incremental updates
|
|
236
|
+
- [ ] Monitor costs with verbose output
|
|
237
|
+
- [ ] Estimate before large jobs
|