@ax-llm/ax 11.0.37 → 11.0.39
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 +98 -8
- package/index.cjs.map +1 -1
- package/index.d.cts +99 -77
- package/index.d.ts +99 -77
- package/index.js +98 -8
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -905,6 +905,9 @@ var AxBaseAI = class {
|
|
|
905
905
|
modelUsage;
|
|
906
906
|
embedModelUsage;
|
|
907
907
|
defaults;
|
|
908
|
+
lastUsedModelConfig;
|
|
909
|
+
lastUsedChatModel;
|
|
910
|
+
lastUsedEmbedModel;
|
|
908
911
|
apiURL;
|
|
909
912
|
name;
|
|
910
913
|
id;
|
|
@@ -994,6 +997,15 @@ var AxBaseAI = class {
|
|
|
994
997
|
getFeatures(model) {
|
|
995
998
|
return typeof this.supportFor === "function" ? this.supportFor(model ?? this.defaults.model) : this.supportFor;
|
|
996
999
|
}
|
|
1000
|
+
getLastUsedChatModel() {
|
|
1001
|
+
return this.lastUsedChatModel;
|
|
1002
|
+
}
|
|
1003
|
+
getLastUsedEmbedModel() {
|
|
1004
|
+
return this.lastUsedEmbedModel;
|
|
1005
|
+
}
|
|
1006
|
+
getLastUsedModelConfig() {
|
|
1007
|
+
return this.lastUsedModelConfig;
|
|
1008
|
+
}
|
|
997
1009
|
// Method to calculate percentiles
|
|
998
1010
|
calculatePercentile(samples, percentile) {
|
|
999
1011
|
if (samples.length === 0) return 0;
|
|
@@ -1116,6 +1128,8 @@ var AxBaseAI = class {
|
|
|
1116
1128
|
functions,
|
|
1117
1129
|
modelConfig
|
|
1118
1130
|
};
|
|
1131
|
+
this.lastUsedChatModel = model;
|
|
1132
|
+
this.lastUsedModelConfig = modelConfig;
|
|
1119
1133
|
const fn = async () => {
|
|
1120
1134
|
const [apiConfig, reqValue] = this.aiImpl.createChatReq(
|
|
1121
1135
|
req,
|
|
@@ -1246,6 +1260,7 @@ var AxBaseAI = class {
|
|
|
1246
1260
|
...embedReq,
|
|
1247
1261
|
embedModel
|
|
1248
1262
|
};
|
|
1263
|
+
this.lastUsedEmbedModel = embedModel;
|
|
1249
1264
|
const fn = async () => {
|
|
1250
1265
|
const [apiConfig, reqValue] = this.aiImpl.createEmbedReq(req);
|
|
1251
1266
|
const res2 = await apiCall(
|
|
@@ -3939,6 +3954,15 @@ var AxAI = class {
|
|
|
3939
3954
|
getModelList() {
|
|
3940
3955
|
return this.ai.getModelList();
|
|
3941
3956
|
}
|
|
3957
|
+
getLastUsedChatModel() {
|
|
3958
|
+
return this.ai.getLastUsedChatModel();
|
|
3959
|
+
}
|
|
3960
|
+
getLastUsedEmbedModel() {
|
|
3961
|
+
return this.ai.getLastUsedEmbedModel();
|
|
3962
|
+
}
|
|
3963
|
+
getLastUsedModelConfig() {
|
|
3964
|
+
return this.ai.getLastUsedModelConfig();
|
|
3965
|
+
}
|
|
3942
3966
|
getMetrics() {
|
|
3943
3967
|
return this.ai.getMetrics();
|
|
3944
3968
|
}
|
|
@@ -6510,7 +6534,10 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6510
6534
|
await assertAssertions(this.asserts, values);
|
|
6511
6535
|
}
|
|
6512
6536
|
if (result.finishReason === "length") {
|
|
6513
|
-
throw new Error(
|
|
6537
|
+
throw new Error(
|
|
6538
|
+
`Max tokens reached before completion
|
|
6539
|
+
Content: ${content}`
|
|
6540
|
+
);
|
|
6514
6541
|
}
|
|
6515
6542
|
}
|
|
6516
6543
|
const funcs = parseFunctionCalls(ai, functionCalls, values, model);
|
|
@@ -6605,7 +6632,10 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6605
6632
|
}
|
|
6606
6633
|
}
|
|
6607
6634
|
if (result.finishReason === "length") {
|
|
6608
|
-
throw new Error(
|
|
6635
|
+
throw new Error(
|
|
6636
|
+
`Max tokens reached before completion
|
|
6637
|
+
Content: ${result.content}`
|
|
6638
|
+
);
|
|
6609
6639
|
}
|
|
6610
6640
|
}
|
|
6611
6641
|
const publicValues = { ...values };
|
|
@@ -6670,7 +6700,7 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6670
6700
|
err = e;
|
|
6671
6701
|
} else if (e instanceof AxAIServiceStreamTerminatedError) {
|
|
6672
6702
|
} else {
|
|
6673
|
-
throw e;
|
|
6703
|
+
throw enhanceError(e, ai, this.signature);
|
|
6674
6704
|
}
|
|
6675
6705
|
if (errorFields) {
|
|
6676
6706
|
handleValidationError(
|
|
@@ -6683,9 +6713,17 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6683
6713
|
}
|
|
6684
6714
|
}
|
|
6685
6715
|
}
|
|
6686
|
-
throw
|
|
6716
|
+
throw enhanceError(
|
|
6717
|
+
new Error(`Unable to fix validation error: ${err?.toString()}`),
|
|
6718
|
+
ai,
|
|
6719
|
+
this.signature
|
|
6720
|
+
);
|
|
6687
6721
|
}
|
|
6688
|
-
throw
|
|
6722
|
+
throw enhanceError(
|
|
6723
|
+
new Error(`Max steps reached: ${maxSteps}`),
|
|
6724
|
+
ai,
|
|
6725
|
+
this.signature
|
|
6726
|
+
);
|
|
6689
6727
|
}
|
|
6690
6728
|
shouldContinueSteps(lastMemItem, stopFunction) {
|
|
6691
6729
|
const stopFunctionExecuted = stopFunction && this.functionsExecuted.has(stopFunction);
|
|
@@ -6756,6 +6794,22 @@ var AxGen = class extends AxProgramWithSignature {
|
|
|
6756
6794
|
});
|
|
6757
6795
|
}
|
|
6758
6796
|
};
|
|
6797
|
+
function enhanceError(e, ai, signature) {
|
|
6798
|
+
const originalError = e instanceof Error ? e : new Error(String(e));
|
|
6799
|
+
const model = ai.getLastUsedChatModel();
|
|
6800
|
+
const modelConfig = ai.getLastUsedModelConfig();
|
|
6801
|
+
const details = [
|
|
6802
|
+
`name=${ai.getName()}`,
|
|
6803
|
+
`model=${model}`,
|
|
6804
|
+
`maxTokens=${modelConfig?.maxTokens ?? "N/A"}`,
|
|
6805
|
+
`streaming=${modelConfig?.stream ?? false}`
|
|
6806
|
+
].join(", ");
|
|
6807
|
+
return new Error(
|
|
6808
|
+
`Generate Failed:${signature.toString()}
|
|
6809
|
+
Details: ${details}`,
|
|
6810
|
+
{ cause: originalError }
|
|
6811
|
+
);
|
|
6812
|
+
}
|
|
6759
6813
|
|
|
6760
6814
|
// prompts/agent.ts
|
|
6761
6815
|
function processChildAgentFunction(childFunction, parentValues, parentInputKeys, modelList, options) {
|
|
@@ -7136,6 +7190,15 @@ var AxBalancer = class _AxBalancer {
|
|
|
7136
7190
|
this.maxBackoffMs = options?.maxBackoffMs ?? 32e3;
|
|
7137
7191
|
this.maxRetries = options?.maxRetries ?? 3;
|
|
7138
7192
|
}
|
|
7193
|
+
getLastUsedChatModel() {
|
|
7194
|
+
return this.currentService.getLastUsedChatModel();
|
|
7195
|
+
}
|
|
7196
|
+
getLastUsedEmbedModel() {
|
|
7197
|
+
return this.currentService.getLastUsedEmbedModel();
|
|
7198
|
+
}
|
|
7199
|
+
getLastUsedModelConfig() {
|
|
7200
|
+
return this.currentService.getLastUsedModelConfig();
|
|
7201
|
+
}
|
|
7139
7202
|
/**
|
|
7140
7203
|
* Service comparator that respects the input order of services.
|
|
7141
7204
|
*/
|
|
@@ -9300,6 +9363,15 @@ var AxMockAIService = class {
|
|
|
9300
9363
|
embed: { count: 0, rate: 0, total: 0 }
|
|
9301
9364
|
}
|
|
9302
9365
|
};
|
|
9366
|
+
getLastUsedChatModel() {
|
|
9367
|
+
throw new Error("Method not implemented.");
|
|
9368
|
+
}
|
|
9369
|
+
getLastUsedEmbedModel() {
|
|
9370
|
+
throw new Error("Method not implemented.");
|
|
9371
|
+
}
|
|
9372
|
+
getLastUsedModelConfig() {
|
|
9373
|
+
throw new Error("Method not implemented.");
|
|
9374
|
+
}
|
|
9303
9375
|
getName() {
|
|
9304
9376
|
return this.config.name ?? "mock-ai-service";
|
|
9305
9377
|
}
|
|
@@ -11209,6 +11281,7 @@ var AxMCPStdioTransport = class {
|
|
|
11209
11281
|
// ai/multiservice.ts
|
|
11210
11282
|
var AxMultiServiceRouter = class {
|
|
11211
11283
|
options;
|
|
11284
|
+
lastUsedService;
|
|
11212
11285
|
services = /* @__PURE__ */ new Map();
|
|
11213
11286
|
/**
|
|
11214
11287
|
* Constructs a new multi-service router.
|
|
@@ -11267,6 +11340,15 @@ var AxMultiServiceRouter = class {
|
|
|
11267
11340
|
}
|
|
11268
11341
|
}
|
|
11269
11342
|
}
|
|
11343
|
+
getLastUsedChatModel() {
|
|
11344
|
+
return this.lastUsedService?.getLastUsedChatModel();
|
|
11345
|
+
}
|
|
11346
|
+
getLastUsedEmbedModel() {
|
|
11347
|
+
return this.lastUsedService?.getLastUsedEmbedModel();
|
|
11348
|
+
}
|
|
11349
|
+
getLastUsedModelConfig() {
|
|
11350
|
+
return this.lastUsedService?.getLastUsedModelConfig();
|
|
11351
|
+
}
|
|
11270
11352
|
/**
|
|
11271
11353
|
* Delegates the chat call to the service matching the provided model key.
|
|
11272
11354
|
*/
|
|
@@ -11279,6 +11361,7 @@ var AxMultiServiceRouter = class {
|
|
|
11279
11361
|
if (!item) {
|
|
11280
11362
|
throw new Error(`No service found for model key: ${modelKey}`);
|
|
11281
11363
|
}
|
|
11364
|
+
this.lastUsedService = item.service;
|
|
11282
11365
|
if (!item.model) {
|
|
11283
11366
|
const { model, ...reqWithoutModel } = req;
|
|
11284
11367
|
return await item.service.chat(reqWithoutModel, options);
|
|
@@ -11297,6 +11380,7 @@ var AxMultiServiceRouter = class {
|
|
|
11297
11380
|
if (!item) {
|
|
11298
11381
|
throw new Error(`No service found for embed model key: ${embedModelKey}`);
|
|
11299
11382
|
}
|
|
11383
|
+
this.lastUsedService = item.service;
|
|
11300
11384
|
if (!item.model) {
|
|
11301
11385
|
const { embedModel, ...reqWithoutEmbedModel } = req;
|
|
11302
11386
|
return await item.service.embed(reqWithoutEmbedModel, options);
|
|
@@ -11351,11 +11435,17 @@ var AxMultiServiceRouter = class {
|
|
|
11351
11435
|
* or falls back to the first service if none has been used.
|
|
11352
11436
|
*/
|
|
11353
11437
|
getMetrics() {
|
|
11354
|
-
|
|
11355
|
-
if (!
|
|
11438
|
+
let serviceInstance = this.lastUsedService;
|
|
11439
|
+
if (!serviceInstance) {
|
|
11440
|
+
const firstServiceEntry = this.services.values().next().value;
|
|
11441
|
+
if (firstServiceEntry) {
|
|
11442
|
+
serviceInstance = "service" in firstServiceEntry ? firstServiceEntry.service : firstServiceEntry;
|
|
11443
|
+
}
|
|
11444
|
+
}
|
|
11445
|
+
if (!serviceInstance) {
|
|
11356
11446
|
throw new Error("No service available to get metrics.");
|
|
11357
11447
|
}
|
|
11358
|
-
return
|
|
11448
|
+
return serviceInstance.getMetrics();
|
|
11359
11449
|
}
|
|
11360
11450
|
/**
|
|
11361
11451
|
* Sets options on all underlying services.
|