@ax-llm/ax 10.0.36 → 10.0.38
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 +22 -9
- package/index.cjs.map +1 -1
- package/index.d.cts +8 -0
- package/index.d.ts +8 -0
- package/index.js +22 -9
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.d.cts
CHANGED
|
@@ -1582,6 +1582,14 @@ declare class AxBalancer implements AxAIService {
|
|
|
1582
1582
|
private currentServiceIndex;
|
|
1583
1583
|
private currentService;
|
|
1584
1584
|
constructor(services: readonly AxAIService[], options?: AxBalancerOptions);
|
|
1585
|
+
/**
|
|
1586
|
+
* Service comparator that respects the input order of services.
|
|
1587
|
+
*/
|
|
1588
|
+
static inputOrderComparator: () => number;
|
|
1589
|
+
/**
|
|
1590
|
+
* Service comparator that sorts services by cost.
|
|
1591
|
+
*/
|
|
1592
|
+
static costComparator: (a: AxAIService, b: AxAIService) => number;
|
|
1585
1593
|
getModelMap(): AxAIModelMap | undefined;
|
|
1586
1594
|
private getNextService;
|
|
1587
1595
|
private reset;
|
package/index.d.ts
CHANGED
|
@@ -1582,6 +1582,14 @@ declare class AxBalancer implements AxAIService {
|
|
|
1582
1582
|
private currentServiceIndex;
|
|
1583
1583
|
private currentService;
|
|
1584
1584
|
constructor(services: readonly AxAIService[], options?: AxBalancerOptions);
|
|
1585
|
+
/**
|
|
1586
|
+
* Service comparator that respects the input order of services.
|
|
1587
|
+
*/
|
|
1588
|
+
static inputOrderComparator: () => number;
|
|
1589
|
+
/**
|
|
1590
|
+
* Service comparator that sorts services by cost.
|
|
1591
|
+
*/
|
|
1592
|
+
static costComparator: (a: AxAIService, b: AxAIService) => number;
|
|
1585
1593
|
getModelMap(): AxAIModelMap | undefined;
|
|
1586
1594
|
private getNextService;
|
|
1587
1595
|
private reset;
|
package/index.js
CHANGED
|
@@ -5323,14 +5323,7 @@ var AxApacheTika = class {
|
|
|
5323
5323
|
};
|
|
5324
5324
|
|
|
5325
5325
|
// ai/balance.ts
|
|
5326
|
-
var
|
|
5327
|
-
const aInfo = a.getModelInfo();
|
|
5328
|
-
const bInfo = b.getModelInfo();
|
|
5329
|
-
const aTotalCost = (aInfo.promptTokenCostPer1M || Infinity) + (aInfo.completionTokenCostPer1M || Infinity);
|
|
5330
|
-
const bTotalCost = (bInfo.promptTokenCostPer1M || Infinity) + (bInfo.completionTokenCostPer1M || Infinity);
|
|
5331
|
-
return aTotalCost - bTotalCost;
|
|
5332
|
-
};
|
|
5333
|
-
var AxBalancer = class {
|
|
5326
|
+
var AxBalancer = class _AxBalancer {
|
|
5334
5327
|
services;
|
|
5335
5328
|
currentServiceIndex = 0;
|
|
5336
5329
|
currentService;
|
|
@@ -5338,13 +5331,29 @@ var AxBalancer = class {
|
|
|
5338
5331
|
if (services.length === 0) {
|
|
5339
5332
|
throw new Error("No AI services provided.");
|
|
5340
5333
|
}
|
|
5341
|
-
this.services = [...services].sort(
|
|
5334
|
+
this.services = [...services].sort(
|
|
5335
|
+
options?.comparator ?? _AxBalancer.costComparator
|
|
5336
|
+
);
|
|
5342
5337
|
const cs = this.services[this.currentServiceIndex];
|
|
5343
5338
|
if (cs === void 0) {
|
|
5344
5339
|
throw new Error("Error initializing the AI services.");
|
|
5345
5340
|
}
|
|
5346
5341
|
this.currentService = cs;
|
|
5347
5342
|
}
|
|
5343
|
+
/**
|
|
5344
|
+
* Service comparator that respects the input order of services.
|
|
5345
|
+
*/
|
|
5346
|
+
static inputOrderComparator = () => 0;
|
|
5347
|
+
/**
|
|
5348
|
+
* Service comparator that sorts services by cost.
|
|
5349
|
+
*/
|
|
5350
|
+
static costComparator = (a, b) => {
|
|
5351
|
+
const aInfo = a.getModelInfo();
|
|
5352
|
+
const bInfo = b.getModelInfo();
|
|
5353
|
+
const aTotalCost = (aInfo.promptTokenCostPer1M || Infinity) + (aInfo.completionTokenCostPer1M || Infinity);
|
|
5354
|
+
const bTotalCost = (bInfo.promptTokenCostPer1M || Infinity) + (bInfo.completionTokenCostPer1M || Infinity);
|
|
5355
|
+
return aTotalCost - bTotalCost;
|
|
5356
|
+
};
|
|
5348
5357
|
getModelMap() {
|
|
5349
5358
|
throw new Error("Method not implemented.");
|
|
5350
5359
|
}
|
|
@@ -5385,9 +5394,11 @@ var AxBalancer = class {
|
|
|
5385
5394
|
try {
|
|
5386
5395
|
return await this.currentService.chat(req, options);
|
|
5387
5396
|
} catch (e) {
|
|
5397
|
+
console.warn(`Service ${this.currentService.getName()} failed`);
|
|
5388
5398
|
if (!this.getNextService()) {
|
|
5389
5399
|
throw e;
|
|
5390
5400
|
}
|
|
5401
|
+
console.warn(`Switching to service ${this.currentService.getName()}`);
|
|
5391
5402
|
}
|
|
5392
5403
|
}
|
|
5393
5404
|
}
|
|
@@ -5397,9 +5408,11 @@ var AxBalancer = class {
|
|
|
5397
5408
|
try {
|
|
5398
5409
|
return await this.currentService.embed(req, options);
|
|
5399
5410
|
} catch (e) {
|
|
5411
|
+
console.warn(`Service ${this.currentService.getName()} failed`);
|
|
5400
5412
|
if (!this.getNextService()) {
|
|
5401
5413
|
throw e;
|
|
5402
5414
|
}
|
|
5415
|
+
console.warn(`Switching to service ${this.currentService.getName()}`);
|
|
5403
5416
|
}
|
|
5404
5417
|
}
|
|
5405
5418
|
}
|