@ax-llm/ax 11.0.53 → 11.0.55
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 +25 -148
- package/index.cjs.map +1 -1
- package/index.d.cts +2 -78
- package/index.d.ts +2 -78
- package/index.js +25 -147
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -75,7 +75,6 @@ __export(index_exports, {
|
|
|
75
75
|
AxAIServiceStreamTerminatedError: () => AxAIServiceStreamTerminatedError,
|
|
76
76
|
AxAIServiceTimeoutError: () => AxAIServiceTimeoutError,
|
|
77
77
|
AxAITogether: () => AxAITogether,
|
|
78
|
-
AxAbortableAI: () => AxAbortableAI,
|
|
79
78
|
AxAgent: () => AxAgent,
|
|
80
79
|
AxApacheTika: () => AxApacheTika,
|
|
81
80
|
AxAssertionError: () => AxAssertionError,
|
|
@@ -3411,7 +3410,7 @@ var AxAIGoogleGeminiImpl = class {
|
|
|
3411
3410
|
candidateCount: 1,
|
|
3412
3411
|
stopSequences: req.modelConfig?.stopSequences ?? this.config.stopSequences,
|
|
3413
3412
|
responseMimeType: "text/plain",
|
|
3414
|
-
...thinkingConfig ? { thinkingConfig } : {}
|
|
3413
|
+
...Object.keys(thinkingConfig).length > 0 ? { thinkingConfig } : {}
|
|
3415
3414
|
};
|
|
3416
3415
|
const safetySettings2 = this.config.safetySettings;
|
|
3417
3416
|
const reqValue = {
|
|
@@ -5980,15 +5979,11 @@ var AxPromptTemplate = class {
|
|
|
5980
5979
|
task;
|
|
5981
5980
|
thoughtFieldName;
|
|
5982
5981
|
functions;
|
|
5983
|
-
strictExamples;
|
|
5984
|
-
optionalOutputFields;
|
|
5985
5982
|
constructor(sig, options, fieldTemplates) {
|
|
5986
5983
|
this.sig = sig;
|
|
5987
5984
|
this.fieldTemplates = fieldTemplates;
|
|
5988
5985
|
this.thoughtFieldName = options?.thoughtFieldName ?? "thought";
|
|
5989
5986
|
this.functions = options?.functions;
|
|
5990
|
-
this.strictExamples = options?.strictExamples ?? false;
|
|
5991
|
-
this.optionalOutputFields = options?.optionalOutputFields ?? [];
|
|
5992
5987
|
const task = [];
|
|
5993
5988
|
const inArgs = renderDescFields(this.sig.getInputFields());
|
|
5994
5989
|
const outArgs = renderDescFields(this.sig.getOutputFields());
|
|
@@ -6158,33 +6153,22 @@ ${outputFields}`);
|
|
|
6158
6153
|
};
|
|
6159
6154
|
renderExamples = (data) => {
|
|
6160
6155
|
const list = [];
|
|
6161
|
-
const
|
|
6162
|
-
isExample: true
|
|
6163
|
-
strictExamples: this.strictExamples,
|
|
6164
|
-
optionalOutputFields: this.optionalOutputFields,
|
|
6165
|
-
isInputField: true
|
|
6166
|
-
};
|
|
6167
|
-
const outputExampleContext = {
|
|
6168
|
-
isExample: true,
|
|
6169
|
-
strictExamples: this.strictExamples,
|
|
6170
|
-
optionalOutputFields: this.optionalOutputFields,
|
|
6171
|
-
isInputField: false
|
|
6156
|
+
const exampleContext = {
|
|
6157
|
+
isExample: true
|
|
6172
6158
|
};
|
|
6173
6159
|
for (const [index, item] of data.entries()) {
|
|
6174
|
-
const renderedInputItem = this.sig.getInputFields().map(
|
|
6175
|
-
|
|
6176
|
-
|
|
6177
|
-
|
|
6178
|
-
|
|
6179
|
-
|
|
6180
|
-
|
|
6181
|
-
)
|
|
6182
|
-
|
|
6183
|
-
|
|
6184
|
-
|
|
6185
|
-
|
|
6186
|
-
}
|
|
6187
|
-
}
|
|
6160
|
+
const renderedInputItem = this.sig.getInputFields().map(
|
|
6161
|
+
(field) => this.renderInField(field, item, {
|
|
6162
|
+
...exampleContext,
|
|
6163
|
+
isInputField: true
|
|
6164
|
+
})
|
|
6165
|
+
).filter((v) => v !== void 0).flat();
|
|
6166
|
+
const renderedOutputItem = this.sig.getOutputFields().map(
|
|
6167
|
+
(field) => this.renderInField(field, item, {
|
|
6168
|
+
...exampleContext,
|
|
6169
|
+
isInputField: false
|
|
6170
|
+
})
|
|
6171
|
+
).filter((v) => v !== void 0).flat();
|
|
6188
6172
|
const renderedItem = [...renderedInputItem, ...renderedOutputItem];
|
|
6189
6173
|
if (index > 0 && renderedItem.length > 0 && renderedItem[0]?.type === "text") {
|
|
6190
6174
|
list.push({ type: "text", text: "---\n\n" });
|
|
@@ -6205,20 +6189,19 @@ ${outputFields}`);
|
|
|
6205
6189
|
const list = [];
|
|
6206
6190
|
const inputFields = this.sig.getInputFields();
|
|
6207
6191
|
const outputFields = this.sig.getOutputFields();
|
|
6192
|
+
const demoContext = {
|
|
6193
|
+
isExample: true
|
|
6194
|
+
};
|
|
6208
6195
|
for (const item of data) {
|
|
6209
6196
|
const inputRenderedItems = inputFields.map(
|
|
6210
6197
|
(field) => this.renderInField(field, item, {
|
|
6211
|
-
|
|
6212
|
-
strictExamples: this.strictExamples,
|
|
6213
|
-
optionalOutputFields: this.optionalOutputFields,
|
|
6198
|
+
...demoContext,
|
|
6214
6199
|
isInputField: true
|
|
6215
6200
|
})
|
|
6216
6201
|
).filter((v) => v !== void 0).flat();
|
|
6217
6202
|
const outputRenderedItems = outputFields.map(
|
|
6218
6203
|
(field) => this.renderInField(field, item, {
|
|
6219
|
-
|
|
6220
|
-
strictExamples: this.strictExamples,
|
|
6221
|
-
optionalOutputFields: this.optionalOutputFields,
|
|
6204
|
+
...demoContext,
|
|
6222
6205
|
isInputField: false
|
|
6223
6206
|
})
|
|
6224
6207
|
).filter((v) => v !== void 0).flat();
|
|
@@ -6434,24 +6417,9 @@ var isEmptyValue = (field, value, context3) => {
|
|
|
6434
6417
|
}
|
|
6435
6418
|
if (!value || (Array.isArray(value) || typeof value === "string") && value.length === 0) {
|
|
6436
6419
|
if (context3?.isExample) {
|
|
6437
|
-
|
|
6438
|
-
if (isInputField) {
|
|
6439
|
-
if (!context3?.strictExamples) {
|
|
6440
|
-
return true;
|
|
6441
|
-
} else {
|
|
6442
|
-
if (field.isOptional || field.isInternal) {
|
|
6443
|
-
return true;
|
|
6444
|
-
}
|
|
6445
|
-
throw new Error(`Value for input field '${field.name}' is required.`);
|
|
6446
|
-
}
|
|
6447
|
-
} else {
|
|
6448
|
-
if (field.isOptional || field.isInternal || context3?.optionalOutputFields?.includes(field.name)) {
|
|
6449
|
-
return true;
|
|
6450
|
-
}
|
|
6451
|
-
throw new Error(`Value for output field '${field.name}' is required.`);
|
|
6452
|
-
}
|
|
6420
|
+
return true;
|
|
6453
6421
|
}
|
|
6454
|
-
if (field.isOptional || field.isInternal
|
|
6422
|
+
if (field.isOptional || field.isInternal) {
|
|
6455
6423
|
return true;
|
|
6456
6424
|
}
|
|
6457
6425
|
const fieldType = context3?.isInputField !== false ? "input" : "output";
|
|
@@ -7782,7 +7750,7 @@ var AxProgramWithSignature = class {
|
|
|
7782
7750
|
const res = {};
|
|
7783
7751
|
for (const f of fields) {
|
|
7784
7752
|
const value = e[f.name];
|
|
7785
|
-
if (value) {
|
|
7753
|
+
if (value !== void 0) {
|
|
7786
7754
|
validateValue(f, value);
|
|
7787
7755
|
res[f.name] = value;
|
|
7788
7756
|
}
|
|
@@ -7915,9 +7883,7 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
7915
7883
|
this.thoughtFieldName = options?.thoughtFieldName ?? "thought";
|
|
7916
7884
|
const promptTemplateOptions = {
|
|
7917
7885
|
functions: options?.functions,
|
|
7918
|
-
thoughtFieldName: this.thoughtFieldName
|
|
7919
|
-
strictExamples: options?.strictExamples,
|
|
7920
|
-
optionalOutputFields: options?.optionalOutputFields
|
|
7886
|
+
thoughtFieldName: this.thoughtFieldName
|
|
7921
7887
|
};
|
|
7922
7888
|
this.promptTemplate = new (options?.promptTemplate ?? AxPromptTemplate)(
|
|
7923
7889
|
this.signature,
|
|
@@ -8281,9 +8247,7 @@ Content: ${result.content}`
|
|
|
8281
8247
|
const promptTemplateClass = this.options?.promptTemplate ?? AxPromptTemplate;
|
|
8282
8248
|
const currentPromptTemplateOptions = {
|
|
8283
8249
|
functions: options.functions,
|
|
8284
|
-
thoughtFieldName: this.thoughtFieldName
|
|
8285
|
-
strictExamples: this.options?.strictExamples,
|
|
8286
|
-
optionalOutputFields: this.options?.optionalOutputFields
|
|
8250
|
+
thoughtFieldName: this.thoughtFieldName
|
|
8287
8251
|
};
|
|
8288
8252
|
this.promptTemplate = new promptTemplateClass(
|
|
8289
8253
|
this.signature,
|
|
@@ -8471,19 +8435,6 @@ Content: ${result.content}`
|
|
|
8471
8435
|
}
|
|
8472
8436
|
setExamples(examples, options) {
|
|
8473
8437
|
super.setExamples(examples, options);
|
|
8474
|
-
if (options?.optionalOutputFields) {
|
|
8475
|
-
const promptTemplateClass = this.options?.promptTemplate ?? AxPromptTemplate;
|
|
8476
|
-
const currentPromptTemplateOptions = {
|
|
8477
|
-
functions: this.functions,
|
|
8478
|
-
thoughtFieldName: this.thoughtFieldName,
|
|
8479
|
-
strictExamples: this.options?.strictExamples,
|
|
8480
|
-
optionalOutputFields: options.optionalOutputFields
|
|
8481
|
-
};
|
|
8482
|
-
this.promptTemplate = new promptTemplateClass(
|
|
8483
|
-
this.signature,
|
|
8484
|
-
currentPromptTemplateOptions
|
|
8485
|
-
);
|
|
8486
|
-
}
|
|
8487
8438
|
}
|
|
8488
8439
|
};
|
|
8489
8440
|
var AxGenerateError = class extends Error {
|
|
@@ -11642,79 +11593,6 @@ var AxTestPrompt = class {
|
|
|
11642
11593
|
}
|
|
11643
11594
|
};
|
|
11644
11595
|
|
|
11645
|
-
// ai/abortable.ts
|
|
11646
|
-
var AxAbortableAI = class {
|
|
11647
|
-
abortController;
|
|
11648
|
-
ai;
|
|
11649
|
-
constructor(ai) {
|
|
11650
|
-
this.ai = ai;
|
|
11651
|
-
this.abortController = new AbortController();
|
|
11652
|
-
}
|
|
11653
|
-
/**
|
|
11654
|
-
* Get the current abort signal
|
|
11655
|
-
*/
|
|
11656
|
-
get signal() {
|
|
11657
|
-
return this.abortController.signal;
|
|
11658
|
-
}
|
|
11659
|
-
/**
|
|
11660
|
-
* Check if the request has been aborted
|
|
11661
|
-
*/
|
|
11662
|
-
get aborted() {
|
|
11663
|
-
return this.abortController.signal.aborted;
|
|
11664
|
-
}
|
|
11665
|
-
/**
|
|
11666
|
-
* Abort the ongoing request
|
|
11667
|
-
* @param reason Optional reason for the abort
|
|
11668
|
-
*/
|
|
11669
|
-
abort(reason) {
|
|
11670
|
-
this.abortController.abort(reason);
|
|
11671
|
-
}
|
|
11672
|
-
/**
|
|
11673
|
-
* Reset the abort controller to allow new requests
|
|
11674
|
-
* This creates a new AbortController, allowing fresh requests
|
|
11675
|
-
*/
|
|
11676
|
-
reset() {
|
|
11677
|
-
this.abortController = new AbortController();
|
|
11678
|
-
}
|
|
11679
|
-
/**
|
|
11680
|
-
* Send a chat request with abort support
|
|
11681
|
-
*/
|
|
11682
|
-
async chat(req, options) {
|
|
11683
|
-
return this.ai.chat(req, {
|
|
11684
|
-
...options,
|
|
11685
|
-
abortSignal: this.abortController.signal
|
|
11686
|
-
});
|
|
11687
|
-
}
|
|
11688
|
-
/**
|
|
11689
|
-
* Send an embed request with abort support
|
|
11690
|
-
*/
|
|
11691
|
-
async embed(req, options) {
|
|
11692
|
-
return this.ai.embed(req, {
|
|
11693
|
-
...options,
|
|
11694
|
-
abortSignal: this.abortController.signal
|
|
11695
|
-
});
|
|
11696
|
-
}
|
|
11697
|
-
/**
|
|
11698
|
-
* Create a timeout-based abort after specified milliseconds
|
|
11699
|
-
* @param timeoutMs Timeout in milliseconds
|
|
11700
|
-
* @param reason Optional reason for the timeout abort
|
|
11701
|
-
* @returns Timeout ID that can be cleared
|
|
11702
|
-
*/
|
|
11703
|
-
abortAfter(timeoutMs, reason = "Request timeout") {
|
|
11704
|
-
return setTimeout(() => {
|
|
11705
|
-
this.abort(reason);
|
|
11706
|
-
}, timeoutMs);
|
|
11707
|
-
}
|
|
11708
|
-
/**
|
|
11709
|
-
* Add an event listener for abort events
|
|
11710
|
-
*/
|
|
11711
|
-
onAbort(callback) {
|
|
11712
|
-
this.abortController.signal.addEventListener("abort", () => {
|
|
11713
|
-
callback(this.abortController.signal.reason);
|
|
11714
|
-
});
|
|
11715
|
-
}
|
|
11716
|
-
};
|
|
11717
|
-
|
|
11718
11596
|
// prompts/cot.ts
|
|
11719
11597
|
var AxChainOfThought = class extends AxGen {
|
|
11720
11598
|
constructor(signature, options) {
|
|
@@ -13617,7 +13495,6 @@ var AxRAG = class extends AxChainOfThought {
|
|
|
13617
13495
|
AxAIServiceStreamTerminatedError,
|
|
13618
13496
|
AxAIServiceTimeoutError,
|
|
13619
13497
|
AxAITogether,
|
|
13620
|
-
AxAbortableAI,
|
|
13621
13498
|
AxAgent,
|
|
13622
13499
|
AxApacheTika,
|
|
13623
13500
|
AxAssertionError,
|