koztv-blog-tools 1.2.1 → 1.2.2
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/dist/index.js +29 -17
- package/dist/index.mjs +29 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -329,24 +329,36 @@ Do not add any explanations or notes.`
|
|
|
329
329
|
}
|
|
330
330
|
];
|
|
331
331
|
const endpoint = apiUrl.endsWith("/") ? `${apiUrl}chat/completions` : `${apiUrl}/chat/completions`;
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
332
|
+
const maxRetries = 3;
|
|
333
|
+
let lastError = null;
|
|
334
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
335
|
+
if (attempt > 0) {
|
|
336
|
+
const delay = 3e3 * Math.pow(2, attempt - 1);
|
|
337
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
338
|
+
}
|
|
339
|
+
const response = await fetch(endpoint, {
|
|
340
|
+
method: "POST",
|
|
341
|
+
headers: {
|
|
342
|
+
"Content-Type": "application/json",
|
|
343
|
+
"Authorization": `Bearer ${apiKey}`
|
|
344
|
+
},
|
|
345
|
+
body: JSON.stringify({
|
|
346
|
+
model,
|
|
347
|
+
messages,
|
|
348
|
+
temperature: 0.3
|
|
349
|
+
})
|
|
350
|
+
});
|
|
351
|
+
if (response.ok) {
|
|
352
|
+
const data = await response.json();
|
|
353
|
+
return data.choices[0]?.message?.content || "";
|
|
354
|
+
}
|
|
345
355
|
const error = await response.text();
|
|
346
|
-
|
|
356
|
+
lastError = new Error(`API error: ${response.status} - ${error}`);
|
|
357
|
+
if (response.status !== 429 && response.status < 500) {
|
|
358
|
+
throw lastError;
|
|
359
|
+
}
|
|
347
360
|
}
|
|
348
|
-
|
|
349
|
-
return data.choices[0]?.message?.content || "";
|
|
361
|
+
throw lastError;
|
|
350
362
|
}
|
|
351
363
|
async function translateTitle(title, options) {
|
|
352
364
|
const translated = await translateContent(title, options);
|
|
@@ -685,7 +697,7 @@ async function processPost(post, options, exportDir) {
|
|
|
685
697
|
} catch (error) {
|
|
686
698
|
onProgress?.(` Error translating to ${targetLang}: ${error.message}`);
|
|
687
699
|
}
|
|
688
|
-
await new Promise((r) => setTimeout(r,
|
|
700
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
689
701
|
}
|
|
690
702
|
} else {
|
|
691
703
|
languages.push({
|
package/dist/index.mjs
CHANGED
|
@@ -272,24 +272,36 @@ Do not add any explanations or notes.`
|
|
|
272
272
|
}
|
|
273
273
|
];
|
|
274
274
|
const endpoint = apiUrl.endsWith("/") ? `${apiUrl}chat/completions` : `${apiUrl}/chat/completions`;
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
275
|
+
const maxRetries = 3;
|
|
276
|
+
let lastError = null;
|
|
277
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
278
|
+
if (attempt > 0) {
|
|
279
|
+
const delay = 3e3 * Math.pow(2, attempt - 1);
|
|
280
|
+
await new Promise((r) => setTimeout(r, delay));
|
|
281
|
+
}
|
|
282
|
+
const response = await fetch(endpoint, {
|
|
283
|
+
method: "POST",
|
|
284
|
+
headers: {
|
|
285
|
+
"Content-Type": "application/json",
|
|
286
|
+
"Authorization": `Bearer ${apiKey}`
|
|
287
|
+
},
|
|
288
|
+
body: JSON.stringify({
|
|
289
|
+
model,
|
|
290
|
+
messages,
|
|
291
|
+
temperature: 0.3
|
|
292
|
+
})
|
|
293
|
+
});
|
|
294
|
+
if (response.ok) {
|
|
295
|
+
const data = await response.json();
|
|
296
|
+
return data.choices[0]?.message?.content || "";
|
|
297
|
+
}
|
|
288
298
|
const error = await response.text();
|
|
289
|
-
|
|
299
|
+
lastError = new Error(`API error: ${response.status} - ${error}`);
|
|
300
|
+
if (response.status !== 429 && response.status < 500) {
|
|
301
|
+
throw lastError;
|
|
302
|
+
}
|
|
290
303
|
}
|
|
291
|
-
|
|
292
|
-
return data.choices[0]?.message?.content || "";
|
|
304
|
+
throw lastError;
|
|
293
305
|
}
|
|
294
306
|
async function translateTitle(title, options) {
|
|
295
307
|
const translated = await translateContent(title, options);
|
|
@@ -628,7 +640,7 @@ async function processPost(post, options, exportDir) {
|
|
|
628
640
|
} catch (error) {
|
|
629
641
|
onProgress?.(` Error translating to ${targetLang}: ${error.message}`);
|
|
630
642
|
}
|
|
631
|
-
await new Promise((r) => setTimeout(r,
|
|
643
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
632
644
|
}
|
|
633
645
|
} else {
|
|
634
646
|
languages.push({
|