orchestrated 0.1.31 → 0.1.33
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/index.js +77 -29
- package/index.js.map +5 -5
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -58842,6 +58842,7 @@ async function getDataset(datasetName, source, options) {
|
|
|
58842
58842
|
cursor = hasExplicitLimit ? undefined : data.nextCursor;
|
|
58843
58843
|
latestHasMore = data.hasMore ?? Boolean(data.nextCursor);
|
|
58844
58844
|
latestLastEvalTimestamp = data.lastEvalTimestamp ?? null;
|
|
58845
|
+
console.log(`[dataset:${datasetName}] page fetched: pageCount=${data.data.length}, runningTotal=${allResults.length}, hasMore=${latestHasMore}, lastEvalTimestamp=${latestLastEvalTimestamp}`);
|
|
58845
58846
|
} catch (error48) {
|
|
58846
58847
|
clearTimeout(timeoutId);
|
|
58847
58848
|
if (error48 instanceof Error && error48.name === "AbortError") {
|
|
@@ -58856,6 +58857,7 @@ async function getDataset(datasetName, source, options) {
|
|
|
58856
58857
|
hasMore: latestHasMore,
|
|
58857
58858
|
lastEvalTimestamp: latestLastEvalTimestamp
|
|
58858
58859
|
};
|
|
58860
|
+
console.log(`[dataset:${datasetName}] pull complete: total=${allResults.length}, hasMore=${latestHasMore}, lastEvalTimestamp=${latestLastEvalTimestamp}`);
|
|
58859
58861
|
return allResults;
|
|
58860
58862
|
}
|
|
58861
58863
|
var getApiUrl = () => {
|
|
@@ -114213,30 +114215,30 @@ class BatchClient {
|
|
|
114213
114215
|
}
|
|
114214
114216
|
console.log(`BatchClient.initialize: ${matchingBatches.length} matching batch(es): ${JSON.stringify(matchingBatches.map((b) => ({ id: b.id, status: b.status })))}`);
|
|
114215
114217
|
const pendingBatches = matchingBatches.filter((batch) => !this.isBatchComplete(batch));
|
|
114216
|
-
const
|
|
114218
|
+
const resultBearingBatches = matchingBatches.filter((batch) => batch.status === "completed" || batch.status === "expired" || batch.status === "cancelled");
|
|
114217
114219
|
if (pendingBatches.length > 0) {
|
|
114218
114220
|
console.log(`BatchClient.initialize: ${pendingBatches.length} pending batch(es), waiting`);
|
|
114219
114221
|
this.hasPendingBatch = true;
|
|
114220
114222
|
this.pendingBatches = pendingBatches;
|
|
114221
114223
|
return;
|
|
114222
114224
|
}
|
|
114223
|
-
if (
|
|
114224
|
-
console.log(`BatchClient.initialize: loading results from ${
|
|
114225
|
+
if (resultBearingBatches.length > 0) {
|
|
114226
|
+
console.log(`BatchClient.initialize: loading results from ${resultBearingBatches.length} batch(es): ${JSON.stringify(resultBearingBatches.map((b) => ({ id: b.id, status: b.status })))}`);
|
|
114225
114227
|
this.hasCompletedBatch = true;
|
|
114226
|
-
this.completedBatches =
|
|
114228
|
+
this.completedBatches = resultBearingBatches;
|
|
114227
114229
|
const allResponses = [];
|
|
114228
|
-
for (const batch of
|
|
114230
|
+
for (const batch of resultBearingBatches) {
|
|
114229
114231
|
try {
|
|
114230
114232
|
const results = await this.getBatchResults(batch.id);
|
|
114231
|
-
console.log(`BatchClient.initialize: loaded ${results.length}
|
|
114233
|
+
console.log(`BatchClient.initialize: loaded ${results.length} result(s) from batch ${batch.id} (status=${batch.status})`);
|
|
114232
114234
|
allResponses.push(...results);
|
|
114233
114235
|
} catch (error48) {
|
|
114234
114236
|
console.warn(`Failed to load results from batch ${batch.id}:`, error48);
|
|
114235
114237
|
}
|
|
114236
114238
|
}
|
|
114237
114239
|
this.responses = allResponses;
|
|
114238
|
-
if (
|
|
114239
|
-
iso.writeln(`${colors.gray}Loaded ${allResponses.length} total results from ${
|
|
114240
|
+
if (resultBearingBatches.length > 1) {
|
|
114241
|
+
iso.writeln(`${colors.gray}Loaded ${allResponses.length} total results from ${resultBearingBatches.length} batches`);
|
|
114240
114242
|
}
|
|
114241
114243
|
}
|
|
114242
114244
|
}
|
|
@@ -115079,6 +115081,7 @@ var traced = {
|
|
|
115079
115081
|
};
|
|
115080
115082
|
|
|
115081
115083
|
// src/evaluator/core.ts
|
|
115084
|
+
var BATCH_MIN_RECORDS = 100;
|
|
115082
115085
|
function deterministicStringify(obj) {
|
|
115083
115086
|
if (obj === null)
|
|
115084
115087
|
return "null";
|
|
@@ -115232,9 +115235,28 @@ function getEvaluationOptions(name, options, state) {
|
|
|
115232
115235
|
let evalClient;
|
|
115233
115236
|
let openaiClient;
|
|
115234
115237
|
const batchProcessor = merged.batchProcessor ?? "OPENAI";
|
|
115238
|
+
const createSyncFallbackClient = () => {
|
|
115239
|
+
if (batchProcessor === "BEDROCK_OPENAI") {
|
|
115240
|
+
if (!state.bedrockRegion || !state.bedrockApiKey || !state.bedrockServiceRoleArn || !state.bedrockModelId) {
|
|
115241
|
+
return;
|
|
115242
|
+
}
|
|
115243
|
+
const { BedrockOpenAI: BedrockOpenAI2 } = (init_bedrock_openai_client(), __toCommonJS(exports_bedrock_openai_client));
|
|
115244
|
+
return new BedrockOpenAI2({
|
|
115245
|
+
baseURL: `https://bedrock-mantle.${state.bedrockRegion}.api.aws/v1`,
|
|
115246
|
+
apiKey: state.bedrockApiKey,
|
|
115247
|
+
defaultHeaders: {
|
|
115248
|
+
"X-Amzn-Bedrock-RoleArn": state.bedrockServiceRoleArn,
|
|
115249
|
+
"X-Amzn-Bedrock-ModelId": state.bedrockModelId
|
|
115250
|
+
}
|
|
115251
|
+
});
|
|
115252
|
+
}
|
|
115253
|
+
const OpenAI5 = __require("openai").default;
|
|
115254
|
+
return new OpenAI5;
|
|
115255
|
+
};
|
|
115235
115256
|
if (execute === "batch") {
|
|
115236
115257
|
if (merged.batchClient) {
|
|
115237
115258
|
batchClient = merged.batchClient;
|
|
115259
|
+
openaiClient = merged.openaiClient ?? createSyncFallbackClient();
|
|
115238
115260
|
} else {
|
|
115239
115261
|
if (batchProcessor === "BEDROCK_OPENAI") {
|
|
115240
115262
|
if (!state.bedrockRegion || !state.bedrockApiKey || !state.bedrockServiceRoleArn || !state.bedrockModelId || !state.bedrockS3Bucket) {
|
|
@@ -115251,27 +115273,28 @@ function getEvaluationOptions(name, options, state) {
|
|
|
115251
115273
|
s3Bucket: state.bedrockS3Bucket
|
|
115252
115274
|
}
|
|
115253
115275
|
});
|
|
115254
|
-
|
|
115255
|
-
openaiClient = new BedrockOpenAI2({
|
|
115256
|
-
baseURL: `https://bedrock-mantle.${state.bedrockRegion}.api.aws/v1`,
|
|
115257
|
-
apiKey: state.bedrockApiKey,
|
|
115258
|
-
defaultHeaders: {
|
|
115259
|
-
"X-Amzn-Bedrock-RoleArn": state.bedrockServiceRoleArn,
|
|
115260
|
-
"X-Amzn-Bedrock-ModelId": state.bedrockModelId
|
|
115261
|
-
}
|
|
115262
|
-
});
|
|
115276
|
+
openaiClient = createSyncFallbackClient();
|
|
115263
115277
|
} else {
|
|
115264
115278
|
batchClient = new BatchClient;
|
|
115265
|
-
|
|
115266
|
-
openaiClient = new OpenAI5;
|
|
115279
|
+
openaiClient = createSyncFallbackClient();
|
|
115267
115280
|
}
|
|
115268
115281
|
}
|
|
115269
115282
|
evalClient = merged.evalClient || new EvalClient({
|
|
115270
115283
|
batchClient
|
|
115271
115284
|
});
|
|
115272
115285
|
} else {
|
|
115273
|
-
|
|
115274
|
-
|
|
115286
|
+
if (merged.openaiClient) {
|
|
115287
|
+
openaiClient = merged.openaiClient;
|
|
115288
|
+
} else if (batchProcessor === "BEDROCK_OPENAI") {
|
|
115289
|
+
openaiClient = createSyncFallbackClient();
|
|
115290
|
+
if (!openaiClient) {
|
|
115291
|
+
throw new Error(`Bedrock configuration is incomplete for sync execution with batchProcessor=BEDROCK_OPENAI. Required: bedrockRegion, bedrockApiKey, bedrockServiceRoleArn, bedrockModelId.
|
|
115292
|
+
` + "Provide via state, environment variables (ORCHESTRATED_BEDROCK_*), or Orchestrated.yaml.");
|
|
115293
|
+
}
|
|
115294
|
+
} else {
|
|
115295
|
+
const OpenAI5 = __require("openai").default;
|
|
115296
|
+
openaiClient = new OpenAI5;
|
|
115297
|
+
}
|
|
115275
115298
|
}
|
|
115276
115299
|
const onResult = merged.onResult;
|
|
115277
115300
|
return {
|
|
@@ -115584,13 +115607,12 @@ async function runEval(name, evaluator, options) {
|
|
|
115584
115607
|
[ATTR_DATASET_SOURCE_TYPE]: data.ctx.sourceType,
|
|
115585
115608
|
[ATTR_EVAL_EXECUTION_METADATA_TEST_CASE_COUNT]: data.ctx.caseCount
|
|
115586
115609
|
});
|
|
115587
|
-
|
|
115588
|
-
execute = "sync";
|
|
115589
|
-
iso.writeln(`ℹ ${data.dataset.length} record(s) is below the 100-record threshold for batch mode. Falling back to sync (individual requests).`);
|
|
115590
|
-
}
|
|
115610
|
+
iso.writeln(`ℹ [batch-trace] dataset resolved: ${data.dataset.length} case(s), sourceType="${data.ctx.sourceType}", dataSourceType="${data.ctx.dataSourceType}", checksum="${data.ctx.checksum}", execute="${execute}", batchProcessor="${batchProcessor}", scorers=${evaluator.scores.length}.`);
|
|
115591
115611
|
if (execute === "batch" && batchClient) {
|
|
115592
115612
|
await batchClient.initialize(name, data.ctx.checksum, data.ctx.dataSourceType);
|
|
115613
|
+
iso.writeln(`ℹ [batch-trace] after initialize: ${batchClient.responses.length} cached response(s) loaded from prior batch(es), hasPendingBatch=${batchClient.hasPendingBatch}, hasCompletedBatch=${batchClient.hasCompletedBatch}.`);
|
|
115593
115614
|
if (batchClient.hasPendingBatch) {
|
|
115615
|
+
iso.writeln("ℹ [batch-trace] a prior batch is still pending — returning early to wait/retry (no new work this run).");
|
|
115594
115616
|
return batchClient.getPending();
|
|
115595
115617
|
}
|
|
115596
115618
|
}
|
|
@@ -115615,11 +115637,37 @@ async function runEval(name, evaluator, options) {
|
|
|
115615
115637
|
if (!jsonl) {
|
|
115616
115638
|
progress.stop();
|
|
115617
115639
|
}
|
|
115640
|
+
if (execute === "batch" && batchClient) {
|
|
115641
|
+
const pendingSoFar = results.filter((r) => r.hasPendingBatch).length;
|
|
115642
|
+
const erroredSoFar = results.filter((r) => r.error).length;
|
|
115643
|
+
const resolvedSoFar = results.length - pendingSoFar - erroredSoFar;
|
|
115644
|
+
iso.writeln(`ℹ [batch-trace] after scoring loop: ${results.length} case(s) processed → ${resolvedSoFar} resolved from cache, ${pendingSoFar} pending (new/changed), ${erroredSoFar} errored. Accumulated ${batchClient.requests.length} batch record(s) across ${evaluator.scores.length} scorer(s)/case, ${batchClient.duplicateCount} duplicate request(s) skipped.`);
|
|
115645
|
+
}
|
|
115618
115646
|
let batch;
|
|
115619
115647
|
if (execute === "batch" && batchClient) {
|
|
115620
|
-
|
|
115621
|
-
|
|
115622
|
-
|
|
115648
|
+
const pendingRequestCount = batchClient.requests.length;
|
|
115649
|
+
const pendingCaseCount = results.filter((r) => r.hasPendingBatch).length;
|
|
115650
|
+
iso.writeln(`ℹ Batch submit decision: ${pendingCaseCount} pending case(s) → ${pendingRequestCount} batch record(s) (minimum ${BATCH_MIN_RECORDS}, sync-fallback client ${options.openaiClient ? "available" : "MISSING"}).`);
|
|
115651
|
+
if (pendingRequestCount > 0 && pendingRequestCount < BATCH_MIN_RECORDS && options.openaiClient) {
|
|
115652
|
+
iso.writeln(`ℹ ${pendingRequestCount} pending request(s) is below the ${BATCH_MIN_RECORDS}-record batch minimum. Running pending case(s) synchronously.`);
|
|
115653
|
+
const syncOptions = { ...effectiveOptions, execute: "sync" };
|
|
115654
|
+
let reranCount = 0;
|
|
115655
|
+
for (let i2 = 0;i2 < results.length; i2++) {
|
|
115656
|
+
if (!results[i2].hasPendingBatch) {
|
|
115657
|
+
continue;
|
|
115658
|
+
}
|
|
115659
|
+
const caseResult = await evaluateDataCase(data.dataset[i2], evaluator, ctx.mutate({ dataset: data.ctx }), syncOptions);
|
|
115660
|
+
results[i2] = caseResult.result;
|
|
115661
|
+
aggregateScorerErrors(errors6, caseResult.errors);
|
|
115662
|
+
reranCount++;
|
|
115663
|
+
}
|
|
115664
|
+
iso.writeln(`ℹ [batch-trace] SYNC-FALLBACK path: re-ran ${reranCount} pending case(s) synchronously; no batch submitted.`);
|
|
115665
|
+
} else {
|
|
115666
|
+
iso.writeln(`ℹ [batch-trace] SUBMIT path: sending ${pendingRequestCount} record(s) to a new batch${options.openaiClient ? "" : " (sync-fallback unavailable, could not run synchronously)"}.`);
|
|
115667
|
+
batch = await batchClient.submit();
|
|
115668
|
+
if (verbose) {
|
|
115669
|
+
console.log(batch);
|
|
115670
|
+
}
|
|
115623
115671
|
}
|
|
115624
115672
|
}
|
|
115625
115673
|
const summary = createEvaluationSummary(name, results, errors6);
|
|
@@ -116080,4 +116128,4 @@ export {
|
|
|
116080
116128
|
Behavioral
|
|
116081
116129
|
};
|
|
116082
116130
|
|
|
116083
|
-
//# debugId=
|
|
116131
|
+
//# debugId=F3E1273F2BB8316964756E2164756E21
|