@ax-llm/ax 10.0.37 → 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 +18 -9
- package/index.cjs.map +1 -1
- package/index.d.cts +8 -0
- package/index.d.ts +8 -0
- package/index.js +18 -9
- package/index.js.map +1 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -5416,14 +5416,7 @@ var AxApacheTika = class {
|
|
|
5416
5416
|
};
|
|
5417
5417
|
|
|
5418
5418
|
// ai/balance.ts
|
|
5419
|
-
var
|
|
5420
|
-
const aInfo = a.getModelInfo();
|
|
5421
|
-
const bInfo = b.getModelInfo();
|
|
5422
|
-
const aTotalCost = (aInfo.promptTokenCostPer1M || Infinity) + (aInfo.completionTokenCostPer1M || Infinity);
|
|
5423
|
-
const bTotalCost = (bInfo.promptTokenCostPer1M || Infinity) + (bInfo.completionTokenCostPer1M || Infinity);
|
|
5424
|
-
return aTotalCost - bTotalCost;
|
|
5425
|
-
};
|
|
5426
|
-
var AxBalancer = class {
|
|
5419
|
+
var AxBalancer = class _AxBalancer {
|
|
5427
5420
|
services;
|
|
5428
5421
|
currentServiceIndex = 0;
|
|
5429
5422
|
currentService;
|
|
@@ -5431,13 +5424,29 @@ var AxBalancer = class {
|
|
|
5431
5424
|
if (services.length === 0) {
|
|
5432
5425
|
throw new Error("No AI services provided.");
|
|
5433
5426
|
}
|
|
5434
|
-
this.services = [...services].sort(
|
|
5427
|
+
this.services = [...services].sort(
|
|
5428
|
+
options?.comparator ?? _AxBalancer.costComparator
|
|
5429
|
+
);
|
|
5435
5430
|
const cs = this.services[this.currentServiceIndex];
|
|
5436
5431
|
if (cs === void 0) {
|
|
5437
5432
|
throw new Error("Error initializing the AI services.");
|
|
5438
5433
|
}
|
|
5439
5434
|
this.currentService = cs;
|
|
5440
5435
|
}
|
|
5436
|
+
/**
|
|
5437
|
+
* Service comparator that respects the input order of services.
|
|
5438
|
+
*/
|
|
5439
|
+
static inputOrderComparator = () => 0;
|
|
5440
|
+
/**
|
|
5441
|
+
* Service comparator that sorts services by cost.
|
|
5442
|
+
*/
|
|
5443
|
+
static costComparator = (a, b) => {
|
|
5444
|
+
const aInfo = a.getModelInfo();
|
|
5445
|
+
const bInfo = b.getModelInfo();
|
|
5446
|
+
const aTotalCost = (aInfo.promptTokenCostPer1M || Infinity) + (aInfo.completionTokenCostPer1M || Infinity);
|
|
5447
|
+
const bTotalCost = (bInfo.promptTokenCostPer1M || Infinity) + (bInfo.completionTokenCostPer1M || Infinity);
|
|
5448
|
+
return aTotalCost - bTotalCost;
|
|
5449
|
+
};
|
|
5441
5450
|
getModelMap() {
|
|
5442
5451
|
throw new Error("Method not implemented.");
|
|
5443
5452
|
}
|