melaka 0.0.0
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/CONTRIBUTING.md +347 -0
- package/LICENSE +21 -0
- package/README.md +57 -0
- package/docs/AI_PROVIDERS.md +343 -0
- package/docs/ARCHITECTURE.md +512 -0
- package/docs/CLI.md +438 -0
- package/docs/CONFIGURATION.md +453 -0
- package/docs/INTEGRATION.md +477 -0
- package/docs/ROADMAP.md +248 -0
- package/package.json +46 -0
- package/packages/ai/README.md +43 -0
- package/packages/ai/package.json +42 -0
- package/packages/ai/src/facade.ts +120 -0
- package/packages/ai/src/index.ts +34 -0
- package/packages/ai/src/prompt.ts +117 -0
- package/packages/ai/src/providers/gemini.ts +185 -0
- package/packages/ai/src/providers/index.ts +9 -0
- package/packages/ai/src/types.ts +134 -0
- package/packages/ai/tsconfig.json +19 -0
- package/packages/cli/README.md +70 -0
- package/packages/cli/package.json +44 -0
- package/packages/cli/src/cli.ts +30 -0
- package/packages/cli/src/commands/deploy.ts +115 -0
- package/packages/cli/src/commands/index.ts +9 -0
- package/packages/cli/src/commands/init.ts +107 -0
- package/packages/cli/src/commands/status.ts +73 -0
- package/packages/cli/src/commands/translate.ts +92 -0
- package/packages/cli/src/commands/validate.ts +69 -0
- package/packages/cli/tsconfig.json +19 -0
- package/packages/core/README.md +46 -0
- package/packages/core/package.json +50 -0
- package/packages/core/src/config.ts +241 -0
- package/packages/core/src/index.ts +111 -0
- package/packages/core/src/schema-generator.ts +263 -0
- package/packages/core/src/schemas.ts +126 -0
- package/packages/core/src/types.ts +481 -0
- package/packages/core/src/utils.ts +343 -0
- package/packages/core/tsconfig.json +19 -0
- package/packages/firestore/README.md +60 -0
- package/packages/firestore/package.json +48 -0
- package/packages/firestore/src/generator.ts +270 -0
- package/packages/firestore/src/i18n.ts +262 -0
- package/packages/firestore/src/index.ts +54 -0
- package/packages/firestore/src/processor.ts +245 -0
- package/packages/firestore/src/queue.ts +202 -0
- package/packages/firestore/src/task-handler.ts +164 -0
- package/packages/firestore/tsconfig.json +19 -0
- package/pnpm-workspace.yaml +2 -0
- package/turbo.json +31 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
# AI Providers
|
|
2
|
+
|
|
3
|
+
Melaka supports multiple AI providers for translation. This document covers setup and configuration for each.
|
|
4
|
+
|
|
5
|
+
## Supported Providers
|
|
6
|
+
|
|
7
|
+
| Provider | Models | Best For |
|
|
8
|
+
|----------|--------|----------|
|
|
9
|
+
| **Gemini** | gemini-2.5-flash, gemini-2.5-pro | Cost-effective, fast translations |
|
|
10
|
+
| **OpenAI** | gpt-4o, gpt-4o-mini | High quality, established |
|
|
11
|
+
| **Claude** | claude-sonnet-4-20250514, claude-opus-4-20250514 | Nuanced, creative translations |
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Gemini (Google)
|
|
16
|
+
|
|
17
|
+
Google's Gemini models via Firebase Genkit.
|
|
18
|
+
|
|
19
|
+
### Setup
|
|
20
|
+
|
|
21
|
+
1. **Enable Gemini API** in Google Cloud Console
|
|
22
|
+
2. **Create API Key** or use Application Default Credentials
|
|
23
|
+
3. **Store API Key** as Firebase secret:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
firebase functions:secrets:set GEMINI_API_KEY
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Configuration
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { defineConfig } from 'melaka';
|
|
33
|
+
|
|
34
|
+
export default defineConfig({
|
|
35
|
+
ai: {
|
|
36
|
+
provider: 'gemini',
|
|
37
|
+
model: 'gemini-2.5-flash', // Recommended
|
|
38
|
+
temperature: 0.3,
|
|
39
|
+
apiKeySecret: 'GEMINI_API_KEY',
|
|
40
|
+
},
|
|
41
|
+
// ...
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Available Models
|
|
46
|
+
|
|
47
|
+
| Model | Speed | Quality | Cost |
|
|
48
|
+
|-------|-------|---------|------|
|
|
49
|
+
| `gemini-2.5-flash` | ⚡⚡⚡ | ★★★★ | $ |
|
|
50
|
+
| `gemini-2.5-pro` | ⚡⚡ | ★★★★★ | $$ |
|
|
51
|
+
| `gemini-2.0-flash` | ⚡⚡⚡ | ★★★ | $ |
|
|
52
|
+
|
|
53
|
+
### Recommendation
|
|
54
|
+
|
|
55
|
+
Use **`gemini-2.5-flash`** for most translation tasks. It's fast, cost-effective, and handles structured output well.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## OpenAI
|
|
60
|
+
|
|
61
|
+
OpenAI's GPT models.
|
|
62
|
+
|
|
63
|
+
### Setup
|
|
64
|
+
|
|
65
|
+
1. **Create API Key** at [platform.openai.com](https://platform.openai.com)
|
|
66
|
+
2. **Store API Key** as Firebase secret:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
firebase functions:secrets:set OPENAI_API_KEY
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Configuration
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import { defineConfig } from 'melaka';
|
|
76
|
+
|
|
77
|
+
export default defineConfig({
|
|
78
|
+
ai: {
|
|
79
|
+
provider: 'openai',
|
|
80
|
+
model: 'gpt-4o-mini', // Cost-effective
|
|
81
|
+
temperature: 0.3,
|
|
82
|
+
apiKeySecret: 'OPENAI_API_KEY',
|
|
83
|
+
},
|
|
84
|
+
// ...
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Available Models
|
|
89
|
+
|
|
90
|
+
| Model | Speed | Quality | Cost |
|
|
91
|
+
|-------|-------|---------|------|
|
|
92
|
+
| `gpt-4o` | ⚡⚡ | ★★★★★ | $$$ |
|
|
93
|
+
| `gpt-4o-mini` | ⚡⚡⚡ | ★★★★ | $ |
|
|
94
|
+
| `gpt-4-turbo` | ⚡⚡ | ★★★★★ | $$ |
|
|
95
|
+
|
|
96
|
+
### Recommendation
|
|
97
|
+
|
|
98
|
+
Use **`gpt-4o-mini`** for cost-effective translations. Use **`gpt-4o`** when quality is critical.
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Claude (Anthropic)
|
|
103
|
+
|
|
104
|
+
Anthropic's Claude models.
|
|
105
|
+
|
|
106
|
+
### Setup
|
|
107
|
+
|
|
108
|
+
1. **Create API Key** at [console.anthropic.com](https://console.anthropic.com)
|
|
109
|
+
2. **Store API Key** as Firebase secret:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
firebase functions:secrets:set ANTHROPIC_API_KEY
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Configuration
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
import { defineConfig } from 'melaka';
|
|
119
|
+
|
|
120
|
+
export default defineConfig({
|
|
121
|
+
ai: {
|
|
122
|
+
provider: 'claude',
|
|
123
|
+
model: 'claude-sonnet-4-20250514',
|
|
124
|
+
temperature: 0.3,
|
|
125
|
+
apiKeySecret: 'ANTHROPIC_API_KEY',
|
|
126
|
+
},
|
|
127
|
+
// ...
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Available Models
|
|
132
|
+
|
|
133
|
+
| Model | Speed | Quality | Cost |
|
|
134
|
+
|-------|-------|---------|------|
|
|
135
|
+
| `claude-sonnet-4-20250514` | ⚡⚡ | ★★★★★ | $$ |
|
|
136
|
+
| `claude-opus-4-20250514` | ⚡ | ★★★★★ | $$$ |
|
|
137
|
+
| `claude-3-5-sonnet-20241022` | ⚡⚡ | ★★★★ | $$ |
|
|
138
|
+
|
|
139
|
+
### Recommendation
|
|
140
|
+
|
|
141
|
+
Use **`claude-sonnet-4-20250514`** for high-quality translations with good speed.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Provider Comparison
|
|
146
|
+
|
|
147
|
+
### Translation Quality
|
|
148
|
+
|
|
149
|
+
For general content translation, all providers perform well. Differences appear in:
|
|
150
|
+
|
|
151
|
+
| Aspect | Gemini | OpenAI | Claude |
|
|
152
|
+
|--------|--------|--------|--------|
|
|
153
|
+
| Accuracy | ★★★★ | ★★★★★ | ★★★★★ |
|
|
154
|
+
| Consistency | ★★★★★ | ★★★★ | ★★★★ |
|
|
155
|
+
| Cultural nuance | ★★★★ | ★★★★ | ★★★★★ |
|
|
156
|
+
| Technical terms | ★★★★ | ★★★★★ | ★★★★ |
|
|
157
|
+
| Markdown handling | ★★★★★ | ★★★★ | ★★★★★ |
|
|
158
|
+
|
|
159
|
+
### Cost Comparison (Approximate)
|
|
160
|
+
|
|
161
|
+
| Provider | Model | Cost per 1M tokens |
|
|
162
|
+
|----------|-------|-------------------|
|
|
163
|
+
| Gemini | gemini-2.5-flash | ~$0.075 |
|
|
164
|
+
| OpenAI | gpt-4o-mini | ~$0.15 |
|
|
165
|
+
| OpenAI | gpt-4o | ~$2.50 |
|
|
166
|
+
| Claude | claude-sonnet-4-20250514 | ~$3.00 |
|
|
167
|
+
|
|
168
|
+
### Speed Comparison
|
|
169
|
+
|
|
170
|
+
| Provider | Model | ~Tokens/sec |
|
|
171
|
+
|----------|-------|-------------|
|
|
172
|
+
| Gemini | gemini-2.5-flash | 150+ |
|
|
173
|
+
| OpenAI | gpt-4o-mini | 100+ |
|
|
174
|
+
| OpenAI | gpt-4o | 50+ |
|
|
175
|
+
| Claude | claude-sonnet-4-20250514 | 80+ |
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Multi-Provider Setup
|
|
180
|
+
|
|
181
|
+
You can configure different providers for different collections:
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
import { defineConfig } from 'melaka';
|
|
185
|
+
|
|
186
|
+
export default defineConfig({
|
|
187
|
+
// Default provider
|
|
188
|
+
ai: {
|
|
189
|
+
provider: 'gemini',
|
|
190
|
+
model: 'gemini-2.5-flash',
|
|
191
|
+
},
|
|
192
|
+
|
|
193
|
+
collections: [
|
|
194
|
+
{
|
|
195
|
+
path: 'articles',
|
|
196
|
+
// Uses default (Gemini)
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
path: 'legal_docs',
|
|
200
|
+
// Override for this collection
|
|
201
|
+
ai: {
|
|
202
|
+
provider: 'openai',
|
|
203
|
+
model: 'gpt-4o', // Higher quality for legal content
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
});
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
## Local Development
|
|
213
|
+
|
|
214
|
+
For local development, use environment variables:
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
# .env.local (do not commit!)
|
|
218
|
+
GEMINI_API_KEY=your-gemini-key
|
|
219
|
+
OPENAI_API_KEY=your-openai-key
|
|
220
|
+
ANTHROPIC_API_KEY=your-anthropic-key
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
Load in your config:
|
|
224
|
+
|
|
225
|
+
```typescript
|
|
226
|
+
import { defineConfig } from 'melaka';
|
|
227
|
+
import * as dotenv from 'dotenv';
|
|
228
|
+
|
|
229
|
+
dotenv.config({ path: '.env.local' });
|
|
230
|
+
|
|
231
|
+
export default defineConfig({
|
|
232
|
+
ai: {
|
|
233
|
+
provider: 'gemini',
|
|
234
|
+
model: 'gemini-2.5-flash',
|
|
235
|
+
apiKey: process.env.GEMINI_API_KEY, // For local dev
|
|
236
|
+
apiKeySecret: 'GEMINI_API_KEY', // For production
|
|
237
|
+
},
|
|
238
|
+
// ...
|
|
239
|
+
});
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Error Handling
|
|
245
|
+
|
|
246
|
+
### Rate Limiting
|
|
247
|
+
|
|
248
|
+
All providers have rate limits. Melaka handles this with:
|
|
249
|
+
|
|
250
|
+
- **Automatic retries** with exponential backoff
|
|
251
|
+
- **Request staggering** across Cloud Tasks
|
|
252
|
+
- **Configurable concurrency** limits
|
|
253
|
+
|
|
254
|
+
### Common Errors
|
|
255
|
+
|
|
256
|
+
| Error | Provider | Solution |
|
|
257
|
+
|-------|----------|----------|
|
|
258
|
+
| `RATE_LIMIT_EXCEEDED` | All | Reduce `maxConcurrency` |
|
|
259
|
+
| `INVALID_API_KEY` | All | Check secret configuration |
|
|
260
|
+
| `MODEL_NOT_FOUND` | All | Verify model name |
|
|
261
|
+
| `CONTEXT_LENGTH_EXCEEDED` | All | Split large documents |
|
|
262
|
+
| `INSUFFICIENT_QUOTA` | OpenAI | Upgrade account or wait |
|
|
263
|
+
|
|
264
|
+
### Handling Large Documents
|
|
265
|
+
|
|
266
|
+
For documents with large text fields:
|
|
267
|
+
|
|
268
|
+
```typescript
|
|
269
|
+
collections: [
|
|
270
|
+
{
|
|
271
|
+
path: 'long_articles',
|
|
272
|
+
// Reduce batch size for large content
|
|
273
|
+
batchSize: 5,
|
|
274
|
+
maxConcurrency: 3,
|
|
275
|
+
},
|
|
276
|
+
],
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
---
|
|
280
|
+
|
|
281
|
+
## Best Practices
|
|
282
|
+
|
|
283
|
+
### 1. Start with Gemini
|
|
284
|
+
|
|
285
|
+
For most use cases, Gemini offers the best cost/performance ratio:
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
ai: {
|
|
289
|
+
provider: 'gemini',
|
|
290
|
+
model: 'gemini-2.5-flash',
|
|
291
|
+
}
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
### 2. Use Low Temperature
|
|
295
|
+
|
|
296
|
+
Lower temperature = more consistent translations:
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
ai: {
|
|
300
|
+
temperature: 0.3, // Recommended for translation
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### 3. Provide Context via Prompts
|
|
305
|
+
|
|
306
|
+
Help the AI understand your content:
|
|
307
|
+
|
|
308
|
+
```typescript
|
|
309
|
+
collections: [
|
|
310
|
+
{
|
|
311
|
+
path: 'recipes',
|
|
312
|
+
prompt: `
|
|
313
|
+
Cooking recipe content.
|
|
314
|
+
Keep measurements in original units.
|
|
315
|
+
Translate ingredient names accurately.
|
|
316
|
+
`,
|
|
317
|
+
},
|
|
318
|
+
],
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### 4. Use Glossaries
|
|
322
|
+
|
|
323
|
+
Ensure consistent terminology:
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
glossary: {
|
|
327
|
+
'checkout': 'checkout',
|
|
328
|
+
'cart': 'troli',
|
|
329
|
+
'Acme Inc': 'Acme Inc', // Don't translate brand
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### 5. Monitor Costs
|
|
334
|
+
|
|
335
|
+
Track usage and set alerts in your provider's dashboard.
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## Next Steps
|
|
340
|
+
|
|
341
|
+
- [Configuration](./CONFIGURATION.md) — Full config reference
|
|
342
|
+
- [CLI Reference](./CLI.md) — Command documentation
|
|
343
|
+
- [Architecture](./ARCHITECTURE.md) — System design
|