transl8-srt 1.0.1 → 1.1.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/README.md CHANGED
@@ -59,9 +59,11 @@ console.log(result.stats);
59
59
  // totalCues: 2,
60
60
  // totalSentences: 1,
61
61
  // totalBatches: 1,
62
+ // failedBatches: [],
62
63
  // inputTokens: 312,
63
64
  // outputTokens: 48,
64
65
  // estimatedCostUsd: 0.0000528,
66
+ // costTracked: true,
65
67
  // durationMs: 843
66
68
  // }
67
69
  ```
@@ -131,6 +133,23 @@ const client = new OpenAI({
131
133
  const result = await translate(content, {targetLang: "es"}, client);
132
134
  ```
133
135
 
136
+ ### Bring custom models - like Deepseek
137
+
138
+ ```typescript
139
+ import OpenAI from "openai";
140
+ import { translate } from "transl8-srt";
141
+
142
+ const client = new OpenAI({
143
+ baseURL: "https://api.deepseek.com",
144
+ apiKey: process.env.DEEPSEEK_API_KEY,
145
+ });
146
+
147
+ const result = await translate(content, {
148
+ targetLang: "fr",
149
+ model: "deepseek-chat", // ← explicitly set — no auto-selection for custom providers
150
+ }, client);
151
+ ```
152
+
134
153
  ---
135
154
 
136
155
  ## Options reference
@@ -149,11 +168,23 @@ interface TranslateOptions {
149
168
  batchSize?: number; // Sentences per API call. Default: 25
150
169
  contextOverlap?: number; // Overlap sentences from prior batch. Default: 4
151
170
  concurrency?: number; // Parallel API requests. Default: 8
171
+ maxBatchTokens?: number; // Soft token budget/batch (~4 chars/token heuristic). Default: 4000
172
+ jsonMode?: boolean; // Request response_format: json_object. Default: true
152
173
  model?: "gpt-4o" | "gpt-4o-mini"; // Auto-selected based on targetLang if omitted
153
174
  primer?: boolean; // AI-inferred style profile. Default: false
154
175
  }
155
176
  ```
156
177
 
178
+ A batch closes as soon as either `batchSize` sentences or `maxBatchTokens`
179
+ (estimated) is reached — whichever comes first. This keeps a batch of a few
180
+ long, run-on sentences from producing an oversized request even though it's
181
+ under the sentence-count cap.
182
+
183
+ If a batch fails after retries, `translate()` does **not** throw — that
184
+ batch's cues keep their original (untranslated) text, and the batch's index
185
+ is reported in `result.stats.failedBatches` so you can detect and re-run
186
+ just the failed portion if needed.
187
+
157
188
  ### Auto model selection
158
189
 
159
190
  | Target language | Auto model |