@semiont/jobs 0.5.12 → 0.5.13
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 +42 -6
- package/dist/index.js.map +1 -1
- package/dist/worker-main.js +153 -20
- package/dist/worker-main.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -419,6 +419,41 @@ function isFailedJob(job) {
|
|
|
419
419
|
function isCancelledJob(job) {
|
|
420
420
|
return job.status === "cancelled";
|
|
421
421
|
}
|
|
422
|
+
|
|
423
|
+
// src/workers/inference-call.ts
|
|
424
|
+
var INFERENCE_TIMEOUT_MS = 10 * 6e4;
|
|
425
|
+
async function withTimeout(work, label) {
|
|
426
|
+
let timer;
|
|
427
|
+
const timedOut = new Promise((_, reject) => {
|
|
428
|
+
timer = setTimeout(() => {
|
|
429
|
+
reject(new Error(
|
|
430
|
+
`Inference call timed out after ${INFERENCE_TIMEOUT_MS / 6e4} minutes (${label}) \u2014 failing the job to keep the claim loop live`
|
|
431
|
+
));
|
|
432
|
+
}, INFERENCE_TIMEOUT_MS);
|
|
433
|
+
timer.unref?.();
|
|
434
|
+
});
|
|
435
|
+
try {
|
|
436
|
+
return await Promise.race([work, timedOut]);
|
|
437
|
+
} catch (err) {
|
|
438
|
+
work.catch(() => {
|
|
439
|
+
});
|
|
440
|
+
throw err;
|
|
441
|
+
} finally {
|
|
442
|
+
clearTimeout(timer);
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function boundedGenerate(client, prompt, maxTokens, temperature, options) {
|
|
446
|
+
return withTimeout(
|
|
447
|
+
client.generateText(prompt, maxTokens, temperature, options),
|
|
448
|
+
`${client.type}:${client.modelId}`
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
function boundedGenerateWithMetadata(client, prompt, maxTokens, temperature, options) {
|
|
452
|
+
return withTimeout(
|
|
453
|
+
client.generateTextWithMetadata(prompt, maxTokens, temperature, options),
|
|
454
|
+
`${client.type}:${client.modelId}`
|
|
455
|
+
);
|
|
456
|
+
}
|
|
422
457
|
function languageName(tag) {
|
|
423
458
|
return getLocaleEnglishName(tag) || tag;
|
|
424
459
|
}
|
|
@@ -900,7 +935,7 @@ var AnnotationDetection = class {
|
|
|
900
935
|
*/
|
|
901
936
|
static async detectComments(content, client, instructions, tone, density, language, sourceLanguage) {
|
|
902
937
|
const prompt = MotivationPrompts.buildCommentPrompt(content, instructions, tone, density, language, sourceLanguage);
|
|
903
|
-
const response = await client
|
|
938
|
+
const response = await boundedGenerateWithMetadata(client, prompt, 3e3, 0.4, { format: "json" });
|
|
904
939
|
assertNotTruncated(response, "comment");
|
|
905
940
|
return MotivationParsers.parseComments(response.text, content);
|
|
906
941
|
}
|
|
@@ -913,7 +948,7 @@ var AnnotationDetection = class {
|
|
|
913
948
|
*/
|
|
914
949
|
static async detectHighlights(content, client, instructions, density, sourceLanguage) {
|
|
915
950
|
const prompt = MotivationPrompts.buildHighlightPrompt(content, instructions, density, sourceLanguage);
|
|
916
|
-
const response = await client
|
|
951
|
+
const response = await boundedGenerateWithMetadata(client, prompt, 2e3, 0.3, { format: "json" });
|
|
917
952
|
assertNotTruncated(response, "highlight");
|
|
918
953
|
return MotivationParsers.parseHighlights(response.text, content);
|
|
919
954
|
}
|
|
@@ -926,7 +961,7 @@ var AnnotationDetection = class {
|
|
|
926
961
|
*/
|
|
927
962
|
static async detectAssessments(content, client, instructions, tone, density, language, sourceLanguage) {
|
|
928
963
|
const prompt = MotivationPrompts.buildAssessmentPrompt(content, instructions, tone, density, language, sourceLanguage);
|
|
929
|
-
const response = await client
|
|
964
|
+
const response = await boundedGenerateWithMetadata(client, prompt, 3e3, 0.3, { format: "json" });
|
|
930
965
|
assertNotTruncated(response, "assessment");
|
|
931
966
|
return MotivationParsers.parseAssessments(response.text, content);
|
|
932
967
|
}
|
|
@@ -957,7 +992,7 @@ var AnnotationDetection = class {
|
|
|
957
992
|
categoryInfo.examples,
|
|
958
993
|
sourceLanguage
|
|
959
994
|
);
|
|
960
|
-
const response = await client
|
|
995
|
+
const response = await boundedGenerateWithMetadata(client, prompt, 4e3, 0.2, { format: "json" });
|
|
961
996
|
assertNotTruncated(response, "tag");
|
|
962
997
|
const parsedTags = MotivationParsers.parseTags(response.text);
|
|
963
998
|
return MotivationParsers.validateTagOffsets(parsedTags, content, category);
|
|
@@ -1013,7 +1048,8 @@ If no entities are found, respond with an empty array [].
|
|
|
1013
1048
|
Example output:
|
|
1014
1049
|
[{"exact":"Alice","entityType":"Person","prefix":"","suffix":" went to"},{"exact":"Paris","entityType":"Location","prefix":"went to ","suffix":" yesterday"}]`;
|
|
1015
1050
|
logger.debug("Sending entity extraction request", { entityTypes: entityTypesDescription });
|
|
1016
|
-
const response = await
|
|
1051
|
+
const response = await boundedGenerateWithMetadata(
|
|
1052
|
+
client,
|
|
1017
1053
|
prompt,
|
|
1018
1054
|
4e3,
|
|
1019
1055
|
// Increased to handle many entities without truncation
|
|
@@ -1263,7 +1299,7 @@ ${formatRequirements}`;
|
|
|
1263
1299
|
temperature: finalTemperature,
|
|
1264
1300
|
maxTokens: finalMaxTokens
|
|
1265
1301
|
});
|
|
1266
|
-
const response = await client
|
|
1302
|
+
const response = await boundedGenerate(client, prompt, finalMaxTokens, finalTemperature);
|
|
1267
1303
|
logger.debug("Got response from inference", { responseLength: response.length });
|
|
1268
1304
|
const result = parseResponse(response);
|
|
1269
1305
|
logger.debug("Parsed response", {
|