@ax-llm/ax 11.0.52 → 11.0.54
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.cjs +222 -55
- package/index.cjs.map +1 -1
- package/index.d.cts +31 -7
- package/index.d.ts +31 -7
- package/index.js +221 -55
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -66,6 +66,7 @@ __export(index_exports, {
|
|
|
66
66
|
AxAIOpenAIResponsesImpl: () => AxAIOpenAIResponsesImpl,
|
|
67
67
|
AxAIReka: () => AxAIReka,
|
|
68
68
|
AxAIRekaModel: () => AxAIRekaModel,
|
|
69
|
+
AxAIServiceAbortedError: () => AxAIServiceAbortedError,
|
|
69
70
|
AxAIServiceAuthenticationError: () => AxAIServiceAuthenticationError,
|
|
70
71
|
AxAIServiceError: () => AxAIServiceError,
|
|
71
72
|
AxAIServiceNetworkError: () => AxAIServiceNetworkError,
|
|
@@ -459,10 +460,25 @@ var AxAIServiceStreamTerminatedError = class extends AxAIServiceError {
|
|
|
459
460
|
};
|
|
460
461
|
var AxAIServiceTimeoutError = class extends AxAIServiceError {
|
|
461
462
|
constructor(url, timeoutMs, requestBody, context3) {
|
|
462
|
-
super(
|
|
463
|
-
timeoutMs
|
|
464
|
-
|
|
465
|
-
|
|
463
|
+
super(
|
|
464
|
+
`Request timed out after ${timeoutMs}ms`,
|
|
465
|
+
url,
|
|
466
|
+
requestBody,
|
|
467
|
+
void 0,
|
|
468
|
+
{ timeoutMs, ...context3 }
|
|
469
|
+
);
|
|
470
|
+
this.name = this.constructor.name;
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
var AxAIServiceAbortedError = class extends AxAIServiceError {
|
|
474
|
+
constructor(url, reason, requestBody, context3) {
|
|
475
|
+
super(
|
|
476
|
+
`Request aborted${reason ? `: ${reason}` : ""}`,
|
|
477
|
+
url,
|
|
478
|
+
requestBody,
|
|
479
|
+
void 0,
|
|
480
|
+
{ abortReason: reason, ...context3 }
|
|
481
|
+
);
|
|
466
482
|
this.name = this.constructor.name;
|
|
467
483
|
}
|
|
468
484
|
};
|
|
@@ -522,9 +538,34 @@ var apiCall = async (api, json) => {
|
|
|
522
538
|
});
|
|
523
539
|
let attempt = 0;
|
|
524
540
|
while (true) {
|
|
525
|
-
const
|
|
541
|
+
const combinedAbortController = new AbortController();
|
|
542
|
+
if (api.abortSignal) {
|
|
543
|
+
if (api.abortSignal.aborted) {
|
|
544
|
+
throw new AxAIServiceAbortedError(
|
|
545
|
+
apiUrl.href,
|
|
546
|
+
api.abortSignal.reason,
|
|
547
|
+
json,
|
|
548
|
+
{ metrics }
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
const userAbortHandler = () => {
|
|
552
|
+
combinedAbortController.abort(
|
|
553
|
+
api.abortSignal.reason || "User aborted request"
|
|
554
|
+
);
|
|
555
|
+
};
|
|
556
|
+
api.abortSignal.addEventListener("abort", userAbortHandler, {
|
|
557
|
+
once: true
|
|
558
|
+
});
|
|
559
|
+
const originalAbort = combinedAbortController.abort.bind(
|
|
560
|
+
combinedAbortController
|
|
561
|
+
);
|
|
562
|
+
combinedAbortController.abort = (reason) => {
|
|
563
|
+
api.abortSignal.removeEventListener("abort", userAbortHandler);
|
|
564
|
+
originalAbort(reason);
|
|
565
|
+
};
|
|
566
|
+
}
|
|
526
567
|
timeoutId = setTimeout(() => {
|
|
527
|
-
|
|
568
|
+
combinedAbortController.abort("Request timeout");
|
|
528
569
|
}, timeoutMs);
|
|
529
570
|
try {
|
|
530
571
|
const res = await (api.fetch ?? fetch)(apiUrl, {
|
|
@@ -536,7 +577,7 @@ var apiCall = async (api, json) => {
|
|
|
536
577
|
...api.headers
|
|
537
578
|
},
|
|
538
579
|
body: JSON.stringify(json),
|
|
539
|
-
signal:
|
|
580
|
+
signal: combinedAbortController.signal
|
|
540
581
|
});
|
|
541
582
|
clearTimeout(timeoutId);
|
|
542
583
|
if (res.status === 401 || res.status === 403) {
|
|
@@ -599,12 +640,12 @@ var apiCall = async (api, json) => {
|
|
|
599
640
|
let lastChunk;
|
|
600
641
|
let chunkCount = 0;
|
|
601
642
|
const trackingStream = new import_web3.TransformStream({
|
|
602
|
-
transform(chunk,
|
|
643
|
+
transform(chunk, controller) {
|
|
603
644
|
lastChunk = chunk;
|
|
604
645
|
chunkCount++;
|
|
605
646
|
metrics.streamChunks = chunkCount;
|
|
606
647
|
metrics.lastChunkTime = Date.now();
|
|
607
|
-
|
|
648
|
+
controller.enqueue(chunk);
|
|
608
649
|
api.span?.addEvent("stream.chunk", {
|
|
609
650
|
"stream.chunks": chunkCount,
|
|
610
651
|
"stream.duration": Date.now() - metrics.startTime,
|
|
@@ -614,7 +655,7 @@ var apiCall = async (api, json) => {
|
|
|
614
655
|
});
|
|
615
656
|
let closed = false;
|
|
616
657
|
return new import_web3.ReadableStream({
|
|
617
|
-
start(
|
|
658
|
+
start(controller) {
|
|
618
659
|
const reader = res.body.pipeThrough(new textDecoderStream()).pipeThrough(new SSEParser()).pipeThrough(trackingStream).getReader();
|
|
619
660
|
async function read() {
|
|
620
661
|
try {
|
|
@@ -623,12 +664,12 @@ var apiCall = async (api, json) => {
|
|
|
623
664
|
if (done) {
|
|
624
665
|
if (!closed) {
|
|
625
666
|
closed = true;
|
|
626
|
-
|
|
667
|
+
controller.close();
|
|
627
668
|
}
|
|
628
669
|
break;
|
|
629
670
|
}
|
|
630
671
|
if (closed) break;
|
|
631
|
-
|
|
672
|
+
controller.enqueue(value);
|
|
632
673
|
}
|
|
633
674
|
} catch (e) {
|
|
634
675
|
const error = e;
|
|
@@ -637,7 +678,7 @@ var apiCall = async (api, json) => {
|
|
|
637
678
|
streamDuration: Date.now() - metrics.startTime
|
|
638
679
|
};
|
|
639
680
|
if (error.name === "AbortError" || error.message?.includes("aborted")) {
|
|
640
|
-
|
|
681
|
+
controller.error(
|
|
641
682
|
new AxAIServiceStreamTerminatedError(
|
|
642
683
|
apiUrl.href,
|
|
643
684
|
json,
|
|
@@ -646,7 +687,7 @@ var apiCall = async (api, json) => {
|
|
|
646
687
|
)
|
|
647
688
|
);
|
|
648
689
|
} else if (error instanceof TypeError && error.message.includes("cancelled")) {
|
|
649
|
-
|
|
690
|
+
controller.error(
|
|
650
691
|
new AxAIServiceStreamTerminatedError(
|
|
651
692
|
apiUrl.href,
|
|
652
693
|
json,
|
|
@@ -658,7 +699,7 @@ var apiCall = async (api, json) => {
|
|
|
658
699
|
)
|
|
659
700
|
);
|
|
660
701
|
} else {
|
|
661
|
-
|
|
702
|
+
controller.error(
|
|
662
703
|
new AxAIServiceNetworkError(
|
|
663
704
|
error,
|
|
664
705
|
apiUrl.href,
|
|
@@ -685,9 +726,18 @@ var apiCall = async (api, json) => {
|
|
|
685
726
|
});
|
|
686
727
|
} catch (error) {
|
|
687
728
|
if (error instanceof Error && error.name === "AbortError") {
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
729
|
+
if (api.abortSignal?.aborted) {
|
|
730
|
+
throw new AxAIServiceAbortedError(
|
|
731
|
+
apiUrl.href,
|
|
732
|
+
api.abortSignal.reason,
|
|
733
|
+
json,
|
|
734
|
+
{ metrics }
|
|
735
|
+
);
|
|
736
|
+
} else {
|
|
737
|
+
throw new AxAIServiceTimeoutError(apiUrl.href, timeoutMs, json, {
|
|
738
|
+
metrics
|
|
739
|
+
});
|
|
740
|
+
}
|
|
691
741
|
}
|
|
692
742
|
if (api.span?.isRecording()) {
|
|
693
743
|
api.span.recordException(error);
|
|
@@ -932,6 +982,7 @@ var AxBaseAI = class {
|
|
|
932
982
|
timeout;
|
|
933
983
|
excludeContentFromTrace;
|
|
934
984
|
models;
|
|
985
|
+
abortSignal;
|
|
935
986
|
modelInfo;
|
|
936
987
|
modelUsage;
|
|
937
988
|
embedModelUsage;
|
|
@@ -992,6 +1043,7 @@ var AxBaseAI = class {
|
|
|
992
1043
|
this.timeout = options.timeout;
|
|
993
1044
|
this.tracer = options.tracer;
|
|
994
1045
|
this.excludeContentFromTrace = options.excludeContentFromTrace;
|
|
1046
|
+
this.abortSignal = options.abortSignal;
|
|
995
1047
|
}
|
|
996
1048
|
getOptions() {
|
|
997
1049
|
return {
|
|
@@ -1000,7 +1052,8 @@ var AxBaseAI = class {
|
|
|
1000
1052
|
fetch: this.fetch,
|
|
1001
1053
|
tracer: this.tracer,
|
|
1002
1054
|
timeout: this.timeout,
|
|
1003
|
-
excludeContentFromTrace: this.excludeContentFromTrace
|
|
1055
|
+
excludeContentFromTrace: this.excludeContentFromTrace,
|
|
1056
|
+
abortSignal: this.abortSignal
|
|
1004
1057
|
};
|
|
1005
1058
|
}
|
|
1006
1059
|
getModelList() {
|
|
@@ -1182,7 +1235,8 @@ var AxBaseAI = class {
|
|
|
1182
1235
|
timeout: this.timeout,
|
|
1183
1236
|
debug,
|
|
1184
1237
|
fetch: this.fetch,
|
|
1185
|
-
span
|
|
1238
|
+
span,
|
|
1239
|
+
abortSignal: options?.abortSignal ?? this.abortSignal
|
|
1186
1240
|
},
|
|
1187
1241
|
reqValue
|
|
1188
1242
|
);
|
|
@@ -1339,7 +1393,8 @@ var AxBaseAI = class {
|
|
|
1339
1393
|
debug,
|
|
1340
1394
|
fetch: this.fetch,
|
|
1341
1395
|
timeout: this.timeout,
|
|
1342
|
-
span
|
|
1396
|
+
span,
|
|
1397
|
+
abortSignal: options?.abortSignal ?? this.abortSignal
|
|
1343
1398
|
},
|
|
1344
1399
|
reqValue
|
|
1345
1400
|
);
|
|
@@ -3355,7 +3410,7 @@ var AxAIGoogleGeminiImpl = class {
|
|
|
3355
3410
|
candidateCount: 1,
|
|
3356
3411
|
stopSequences: req.modelConfig?.stopSequences ?? this.config.stopSequences,
|
|
3357
3412
|
responseMimeType: "text/plain",
|
|
3358
|
-
...thinkingConfig ? { thinkingConfig } : {}
|
|
3413
|
+
...Object.keys(thinkingConfig).length > 0 ? { thinkingConfig } : {}
|
|
3359
3414
|
};
|
|
3360
3415
|
const safetySettings2 = this.config.safetySettings;
|
|
3361
3416
|
const reqValue = {
|
|
@@ -5631,6 +5686,8 @@ var validateValue = (field, value) => {
|
|
|
5631
5686
|
const ft = field.type ?? { name: "string", isArray: false };
|
|
5632
5687
|
const validateSingleValue = (expectedType, val) => {
|
|
5633
5688
|
switch (expectedType) {
|
|
5689
|
+
case "class":
|
|
5690
|
+
return typeof val === "string";
|
|
5634
5691
|
case "code":
|
|
5635
5692
|
return typeof val === "string";
|
|
5636
5693
|
case "string":
|
|
@@ -5669,7 +5726,7 @@ var validateValue = (field, value) => {
|
|
|
5669
5726
|
}
|
|
5670
5727
|
if (msg) {
|
|
5671
5728
|
throw new Error(
|
|
5672
|
-
`Validation failed: Expected '${field.name}' to be
|
|
5729
|
+
`Validation failed: Expected '${field.name}' to be type '${msg}' instead got '${value}'`
|
|
5673
5730
|
);
|
|
5674
5731
|
}
|
|
5675
5732
|
return;
|
|
@@ -5694,7 +5751,7 @@ var validateValue = (field, value) => {
|
|
|
5694
5751
|
}
|
|
5695
5752
|
if (msg) {
|
|
5696
5753
|
throw new Error(
|
|
5697
|
-
`Validation failed: Expected '${field.name}' to be
|
|
5754
|
+
`Validation failed: Expected '${field.name}' to be type '${msg}' instead got '${value}'`
|
|
5698
5755
|
);
|
|
5699
5756
|
}
|
|
5700
5757
|
return;
|
|
@@ -5715,8 +5772,9 @@ var validateValue = (field, value) => {
|
|
|
5715
5772
|
isValid = validateSingleValue(ft.name, value);
|
|
5716
5773
|
}
|
|
5717
5774
|
if (!isValid) {
|
|
5775
|
+
const gotType = Array.isArray(value) ? "array" : typeof value;
|
|
5718
5776
|
throw new Error(
|
|
5719
|
-
`Validation failed: Expected '${field.name}' to be a ${field.type?.isArray ? "an array of " : ""}${ft.name} instead got '${
|
|
5777
|
+
`Validation failed: Expected '${field.name}' to be a ${field.type?.isArray ? "an array of " : ""}${ft.name} instead got '${gotType}' (${JSON.stringify(value)})`
|
|
5720
5778
|
);
|
|
5721
5779
|
}
|
|
5722
5780
|
};
|
|
@@ -5921,11 +5979,15 @@ var AxPromptTemplate = class {
|
|
|
5921
5979
|
task;
|
|
5922
5980
|
thoughtFieldName;
|
|
5923
5981
|
functions;
|
|
5982
|
+
strictExamples;
|
|
5983
|
+
optionalOutputFields;
|
|
5924
5984
|
constructor(sig, options, fieldTemplates) {
|
|
5925
5985
|
this.sig = sig;
|
|
5926
5986
|
this.fieldTemplates = fieldTemplates;
|
|
5927
5987
|
this.thoughtFieldName = options?.thoughtFieldName ?? "thought";
|
|
5928
5988
|
this.functions = options?.functions;
|
|
5989
|
+
this.strictExamples = options?.strictExamples ?? false;
|
|
5990
|
+
this.optionalOutputFields = options?.optionalOutputFields ?? [];
|
|
5929
5991
|
const task = [];
|
|
5930
5992
|
const inArgs = renderDescFields(this.sig.getInputFields());
|
|
5931
5993
|
const outArgs = renderDescFields(this.sig.getOutputFields());
|
|
@@ -6095,13 +6157,32 @@ ${outputFields}`);
|
|
|
6095
6157
|
};
|
|
6096
6158
|
renderExamples = (data) => {
|
|
6097
6159
|
const list = [];
|
|
6160
|
+
const inputExampleContext = {
|
|
6161
|
+
isExample: true,
|
|
6162
|
+
strictExamples: this.strictExamples,
|
|
6163
|
+
optionalOutputFields: this.optionalOutputFields,
|
|
6164
|
+
isInputField: true
|
|
6165
|
+
};
|
|
6166
|
+
const outputExampleContext = {
|
|
6167
|
+
isExample: true,
|
|
6168
|
+
strictExamples: this.strictExamples,
|
|
6169
|
+
optionalOutputFields: this.optionalOutputFields,
|
|
6170
|
+
isInputField: false
|
|
6171
|
+
};
|
|
6098
6172
|
for (const [index, item] of data.entries()) {
|
|
6099
|
-
const renderedInputItem = this.sig.getInputFields().map((field) => this.renderInField(field, item)).filter((v) => v !== void 0).flat();
|
|
6100
|
-
const
|
|
6173
|
+
const renderedInputItem = this.sig.getInputFields().map((field) => this.renderInField(field, item, inputExampleContext)).filter((v) => v !== void 0).flat();
|
|
6174
|
+
const outputFields = this.sig.getOutputFields();
|
|
6175
|
+
const renderedOutputItem = outputFields.map((field) => this.renderInField(field, item, outputExampleContext)).filter((v) => v !== void 0).flat();
|
|
6101
6176
|
if (renderedOutputItem.length === 0) {
|
|
6102
|
-
|
|
6103
|
-
|
|
6177
|
+
const missingFields = outputFields.filter((field) => !item[field.name]);
|
|
6178
|
+
const allMissingFieldsAreOptional = missingFields.every(
|
|
6179
|
+
(field) => this.optionalOutputFields.includes(field.name)
|
|
6104
6180
|
);
|
|
6181
|
+
if (!allMissingFieldsAreOptional) {
|
|
6182
|
+
throw new Error(
|
|
6183
|
+
`Output fields are required in examples: index: ${index}, data: ${JSON.stringify(item)}`
|
|
6184
|
+
);
|
|
6185
|
+
}
|
|
6105
6186
|
}
|
|
6106
6187
|
const renderedItem = [...renderedInputItem, ...renderedOutputItem];
|
|
6107
6188
|
if (index > 0 && renderedItem.length > 0 && renderedItem[0]?.type === "text") {
|
|
@@ -6121,9 +6202,26 @@ ${outputFields}`);
|
|
|
6121
6202
|
};
|
|
6122
6203
|
renderDemos = (data) => {
|
|
6123
6204
|
const list = [];
|
|
6124
|
-
const
|
|
6205
|
+
const inputFields = this.sig.getInputFields();
|
|
6206
|
+
const outputFields = this.sig.getOutputFields();
|
|
6125
6207
|
for (const item of data) {
|
|
6126
|
-
const
|
|
6208
|
+
const inputRenderedItems = inputFields.map(
|
|
6209
|
+
(field) => this.renderInField(field, item, {
|
|
6210
|
+
isExample: true,
|
|
6211
|
+
strictExamples: this.strictExamples,
|
|
6212
|
+
optionalOutputFields: this.optionalOutputFields,
|
|
6213
|
+
isInputField: true
|
|
6214
|
+
})
|
|
6215
|
+
).filter((v) => v !== void 0).flat();
|
|
6216
|
+
const outputRenderedItems = outputFields.map(
|
|
6217
|
+
(field) => this.renderInField(field, item, {
|
|
6218
|
+
isExample: true,
|
|
6219
|
+
strictExamples: this.strictExamples,
|
|
6220
|
+
optionalOutputFields: this.optionalOutputFields,
|
|
6221
|
+
isInputField: false
|
|
6222
|
+
})
|
|
6223
|
+
).filter((v) => v !== void 0).flat();
|
|
6224
|
+
const renderedItem = [...inputRenderedItems, ...outputRenderedItems];
|
|
6127
6225
|
renderedItem.slice(0, -1).forEach((v) => {
|
|
6128
6226
|
if ("text" in v) {
|
|
6129
6227
|
v.text = v.text + "\n";
|
|
@@ -6137,15 +6235,15 @@ ${outputFields}`);
|
|
|
6137
6235
|
return list;
|
|
6138
6236
|
};
|
|
6139
6237
|
renderInputFields = (values) => {
|
|
6140
|
-
const renderedItems = this.sig.getInputFields().map((field) => this.renderInField(field, values)).filter((v) => v !== void 0).flat();
|
|
6238
|
+
const renderedItems = this.sig.getInputFields().map((field) => this.renderInField(field, values, void 0)).filter((v) => v !== void 0).flat();
|
|
6141
6239
|
renderedItems.filter((v) => v.type === "text").forEach((v) => {
|
|
6142
6240
|
v.text = v.text + "\n";
|
|
6143
6241
|
});
|
|
6144
6242
|
return renderedItems;
|
|
6145
6243
|
};
|
|
6146
|
-
renderInField = (field, values) => {
|
|
6244
|
+
renderInField = (field, values, context3) => {
|
|
6147
6245
|
const value = values[field.name];
|
|
6148
|
-
if (isEmptyValue(field, value)) {
|
|
6246
|
+
if (isEmptyValue(field, value, context3)) {
|
|
6149
6247
|
return;
|
|
6150
6248
|
}
|
|
6151
6249
|
if (field.type) {
|
|
@@ -6329,15 +6427,34 @@ function combineConsecutiveStrings(separator) {
|
|
|
6329
6427
|
return acc;
|
|
6330
6428
|
};
|
|
6331
6429
|
}
|
|
6332
|
-
var isEmptyValue = (field, value) => {
|
|
6430
|
+
var isEmptyValue = (field, value, context3) => {
|
|
6333
6431
|
if (typeof value === "boolean") {
|
|
6334
6432
|
return false;
|
|
6335
6433
|
}
|
|
6336
6434
|
if (!value || (Array.isArray(value) || typeof value === "string") && value.length === 0) {
|
|
6337
|
-
if (
|
|
6435
|
+
if (context3?.isExample) {
|
|
6436
|
+
const isInputField = context3?.isInputField ?? true;
|
|
6437
|
+
if (isInputField) {
|
|
6438
|
+
if (!context3?.strictExamples) {
|
|
6439
|
+
return true;
|
|
6440
|
+
} else {
|
|
6441
|
+
if (field.isOptional || field.isInternal) {
|
|
6442
|
+
return true;
|
|
6443
|
+
}
|
|
6444
|
+
throw new Error(`Value for input field '${field.name}' is required.`);
|
|
6445
|
+
}
|
|
6446
|
+
} else {
|
|
6447
|
+
if (field.isOptional || field.isInternal || context3?.optionalOutputFields?.includes(field.name)) {
|
|
6448
|
+
return true;
|
|
6449
|
+
}
|
|
6450
|
+
throw new Error(`Value for output field '${field.name}' is required.`);
|
|
6451
|
+
}
|
|
6452
|
+
}
|
|
6453
|
+
if (field.isOptional || field.isInternal || context3?.optionalOutputFields?.includes(field.name)) {
|
|
6338
6454
|
return true;
|
|
6339
6455
|
}
|
|
6340
|
-
|
|
6456
|
+
const fieldType = context3?.isInputField !== false ? "input" : "output";
|
|
6457
|
+
throw new Error(`Value for ${fieldType} field '${field.name}' is required.`);
|
|
6341
6458
|
}
|
|
6342
6459
|
return false;
|
|
6343
6460
|
};
|
|
@@ -7597,6 +7714,7 @@ var AxProgramWithSignature = class {
|
|
|
7597
7714
|
signature;
|
|
7598
7715
|
sigHash;
|
|
7599
7716
|
examples;
|
|
7717
|
+
examplesOptions;
|
|
7600
7718
|
demos;
|
|
7601
7719
|
trace;
|
|
7602
7720
|
usage = [];
|
|
@@ -7638,16 +7756,16 @@ var AxProgramWithSignature = class {
|
|
|
7638
7756
|
this.key.id = [parentId, this.key.id].join("/");
|
|
7639
7757
|
}
|
|
7640
7758
|
}
|
|
7641
|
-
setExamples(examples) {
|
|
7642
|
-
this._setExamples(examples);
|
|
7759
|
+
setExamples(examples, options) {
|
|
7760
|
+
this._setExamples(examples, options);
|
|
7643
7761
|
if (!("programId" in examples)) {
|
|
7644
7762
|
return;
|
|
7645
7763
|
}
|
|
7646
7764
|
for (const child of this.children) {
|
|
7647
|
-
child.setExamples(examples);
|
|
7765
|
+
child.setExamples(examples, options);
|
|
7648
7766
|
}
|
|
7649
7767
|
}
|
|
7650
|
-
_setExamples(examples) {
|
|
7768
|
+
_setExamples(examples, options) {
|
|
7651
7769
|
let traces = [];
|
|
7652
7770
|
if ("programId" in examples && examples.programId === this.key.id) {
|
|
7653
7771
|
traces = examples.traces;
|
|
@@ -7656,6 +7774,7 @@ var AxProgramWithSignature = class {
|
|
|
7656
7774
|
traces = examples;
|
|
7657
7775
|
}
|
|
7658
7776
|
if (traces) {
|
|
7777
|
+
this.examplesOptions = options;
|
|
7659
7778
|
const sig = this.signature;
|
|
7660
7779
|
const fields = [...sig.getInputFields(), ...sig.getOutputFields()];
|
|
7661
7780
|
this.examples = traces.map((e) => {
|
|
@@ -7736,12 +7855,12 @@ var AxProgram = class {
|
|
|
7736
7855
|
this.key.id = [parentId, this.key.id].join("/");
|
|
7737
7856
|
}
|
|
7738
7857
|
}
|
|
7739
|
-
setExamples(examples) {
|
|
7858
|
+
setExamples(examples, options) {
|
|
7740
7859
|
if (!("programId" in examples)) {
|
|
7741
7860
|
return;
|
|
7742
7861
|
}
|
|
7743
7862
|
for (const child of this.children) {
|
|
7744
|
-
child.setExamples(examples);
|
|
7863
|
+
child.setExamples(examples, options);
|
|
7745
7864
|
}
|
|
7746
7865
|
}
|
|
7747
7866
|
getTraces() {
|
|
@@ -7795,7 +7914,9 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
7795
7914
|
this.thoughtFieldName = options?.thoughtFieldName ?? "thought";
|
|
7796
7915
|
const promptTemplateOptions = {
|
|
7797
7916
|
functions: options?.functions,
|
|
7798
|
-
thoughtFieldName: this.thoughtFieldName
|
|
7917
|
+
thoughtFieldName: this.thoughtFieldName,
|
|
7918
|
+
strictExamples: options?.strictExamples,
|
|
7919
|
+
optionalOutputFields: options?.optionalOutputFields
|
|
7799
7920
|
};
|
|
7800
7921
|
this.promptTemplate = new (options?.promptTemplate ?? AxPromptTemplate)(
|
|
7801
7922
|
this.signature,
|
|
@@ -7881,7 +8002,8 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
7881
8002
|
stream,
|
|
7882
8003
|
debug: false,
|
|
7883
8004
|
thinkingTokenBudget,
|
|
7884
|
-
traceContext
|
|
8005
|
+
traceContext,
|
|
8006
|
+
abortSignal: options?.abortSignal
|
|
7885
8007
|
}
|
|
7886
8008
|
);
|
|
7887
8009
|
return res;
|
|
@@ -8158,7 +8280,9 @@ Content: ${result.content}`
|
|
|
8158
8280
|
const promptTemplateClass = this.options?.promptTemplate ?? AxPromptTemplate;
|
|
8159
8281
|
const currentPromptTemplateOptions = {
|
|
8160
8282
|
functions: options.functions,
|
|
8161
|
-
thoughtFieldName: this.thoughtFieldName
|
|
8283
|
+
thoughtFieldName: this.thoughtFieldName,
|
|
8284
|
+
strictExamples: this.options?.strictExamples,
|
|
8285
|
+
optionalOutputFields: this.options?.optionalOutputFields
|
|
8162
8286
|
};
|
|
8163
8287
|
this.promptTemplate = new promptTemplateClass(
|
|
8164
8288
|
this.signature,
|
|
@@ -8344,6 +8468,22 @@ Content: ${result.content}`
|
|
|
8344
8468
|
stream: true
|
|
8345
8469
|
});
|
|
8346
8470
|
}
|
|
8471
|
+
setExamples(examples, options) {
|
|
8472
|
+
super.setExamples(examples, options);
|
|
8473
|
+
if (options?.optionalOutputFields) {
|
|
8474
|
+
const promptTemplateClass = this.options?.promptTemplate ?? AxPromptTemplate;
|
|
8475
|
+
const currentPromptTemplateOptions = {
|
|
8476
|
+
functions: this.functions,
|
|
8477
|
+
thoughtFieldName: this.thoughtFieldName,
|
|
8478
|
+
strictExamples: this.options?.strictExamples,
|
|
8479
|
+
optionalOutputFields: options.optionalOutputFields
|
|
8480
|
+
};
|
|
8481
|
+
this.promptTemplate = new promptTemplateClass(
|
|
8482
|
+
this.signature,
|
|
8483
|
+
currentPromptTemplateOptions
|
|
8484
|
+
);
|
|
8485
|
+
}
|
|
8486
|
+
}
|
|
8347
8487
|
};
|
|
8348
8488
|
var AxGenerateError = class extends Error {
|
|
8349
8489
|
details;
|
|
@@ -8474,8 +8614,8 @@ var AxAgent = class {
|
|
|
8474
8614
|
this.func.parameters = addModelParameter(this.func.parameters, mm);
|
|
8475
8615
|
}
|
|
8476
8616
|
}
|
|
8477
|
-
setExamples(examples) {
|
|
8478
|
-
this.program.setExamples(examples);
|
|
8617
|
+
setExamples(examples, options) {
|
|
8618
|
+
this.program.setExamples(examples, options);
|
|
8479
8619
|
}
|
|
8480
8620
|
setId(id) {
|
|
8481
8621
|
this.program.setId(id);
|
|
@@ -9769,7 +9909,12 @@ var AxDBManager = class {
|
|
|
9769
9909
|
const bs = options?.batchSize ?? 10;
|
|
9770
9910
|
for (let i = 0; i < chunks.length; i += bs) {
|
|
9771
9911
|
const batch = chunks.slice(i, i + bs);
|
|
9772
|
-
const ret = await this.ai.embed(
|
|
9912
|
+
const ret = await this.ai.embed(
|
|
9913
|
+
{ texts: batch },
|
|
9914
|
+
{
|
|
9915
|
+
abortSignal: options?.abortSignal
|
|
9916
|
+
}
|
|
9917
|
+
);
|
|
9773
9918
|
const embeddings = ret.embeddings.map((embedding, index) => ({
|
|
9774
9919
|
id: `chunk_${Date.now() + index}`,
|
|
9775
9920
|
// Unique ID for each chunk, adjusted by index
|
|
@@ -9785,7 +9930,10 @@ var AxDBManager = class {
|
|
|
9785
9930
|
throw new Error(`Error processing text: ${error}`);
|
|
9786
9931
|
}
|
|
9787
9932
|
};
|
|
9788
|
-
query = async (query, {
|
|
9933
|
+
query = async (query, {
|
|
9934
|
+
topPercent,
|
|
9935
|
+
abortSignal
|
|
9936
|
+
} = {}) => {
|
|
9789
9937
|
const texts = Array.isArray(query) ? query : [query];
|
|
9790
9938
|
if (typeof texts[0] === "string" && this.rewriter) {
|
|
9791
9939
|
for (const [i, text] of texts.entries()) {
|
|
@@ -9797,7 +9945,12 @@ var AxDBManager = class {
|
|
|
9797
9945
|
}
|
|
9798
9946
|
let queries;
|
|
9799
9947
|
if (typeof texts[0] === "string") {
|
|
9800
|
-
const embedResults = await this.ai.embed(
|
|
9948
|
+
const embedResults = await this.ai.embed(
|
|
9949
|
+
{ texts },
|
|
9950
|
+
{
|
|
9951
|
+
abortSignal
|
|
9952
|
+
}
|
|
9953
|
+
);
|
|
9801
9954
|
queries = embedResults.embeddings.map(
|
|
9802
9955
|
(values) => this.db.query({ table, values })
|
|
9803
9956
|
);
|
|
@@ -11392,9 +11545,14 @@ var AxSimpleClassifier = class {
|
|
|
11392
11545
|
setState(state) {
|
|
11393
11546
|
this.db.setDB(state);
|
|
11394
11547
|
}
|
|
11395
|
-
setClasses = async (classes) => {
|
|
11548
|
+
setClasses = async (classes, options) => {
|
|
11396
11549
|
for (const c of classes) {
|
|
11397
|
-
const ret = await this.ai.embed(
|
|
11550
|
+
const ret = await this.ai.embed(
|
|
11551
|
+
{ texts: c.getContext() },
|
|
11552
|
+
{
|
|
11553
|
+
abortSignal: options?.abortSignal
|
|
11554
|
+
}
|
|
11555
|
+
);
|
|
11398
11556
|
await this.db.upsert({
|
|
11399
11557
|
id: c.getName(),
|
|
11400
11558
|
table: "classes",
|
|
@@ -11403,7 +11561,12 @@ var AxSimpleClassifier = class {
|
|
|
11403
11561
|
}
|
|
11404
11562
|
};
|
|
11405
11563
|
async forward(text, options) {
|
|
11406
|
-
const { embeddings } = await this.ai.embed(
|
|
11564
|
+
const { embeddings } = await this.ai.embed(
|
|
11565
|
+
{ texts: [text] },
|
|
11566
|
+
{
|
|
11567
|
+
abortSignal: options?.abortSignal
|
|
11568
|
+
}
|
|
11569
|
+
);
|
|
11407
11570
|
const matches = await this.db.query({
|
|
11408
11571
|
table: "classes",
|
|
11409
11572
|
values: embeddings[0]
|
|
@@ -11604,7 +11767,10 @@ var AxEmbeddingAdapter = class {
|
|
|
11604
11767
|
async embedAdapter(text, extra) {
|
|
11605
11768
|
const embedRes = await this.aiService.embed(
|
|
11606
11769
|
{ texts: [text] },
|
|
11607
|
-
{
|
|
11770
|
+
{
|
|
11771
|
+
sessionId: extra?.sessionId,
|
|
11772
|
+
abortSignal: extra?.abortSignal
|
|
11773
|
+
}
|
|
11608
11774
|
);
|
|
11609
11775
|
const embeds = embedRes.embeddings.at(0);
|
|
11610
11776
|
if (!embeds) {
|
|
@@ -13368,6 +13534,7 @@ var AxRAG = class extends AxChainOfThought {
|
|
|
13368
13534
|
AxAIOpenAIResponsesImpl,
|
|
13369
13535
|
AxAIReka,
|
|
13370
13536
|
AxAIRekaModel,
|
|
13537
|
+
AxAIServiceAbortedError,
|
|
13371
13538
|
AxAIServiceAuthenticationError,
|
|
13372
13539
|
AxAIServiceError,
|
|
13373
13540
|
AxAIServiceNetworkError,
|