@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.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 axCostComparator = (a, b) => {
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(options?.comparator ?? axCostComparator);
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
  }