@stll/ai-catalog 0.3.2 → 0.5.0
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/dist/benchmark-frontier.d.ts +78 -0
- package/dist/benchmark-frontier.js +125 -0
- package/dist/benchmarks.d.ts +593 -0
- package/dist/benchmarks.js +611 -0
- package/dist/index-D5gnRT1S.d.ts +1664 -0
- package/dist/index.d.ts +2 -1573
- package/dist/index.js +2 -2048
- package/dist/src-Dn6XqN2_.js +2138 -0
- package/package.json +13 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { D as ReasoningEffort, a as BYOKProvider } from "./index-D5gnRT1S.js";
|
|
2
|
+
//#region src/benchmark-frontier.d.ts
|
|
3
|
+
export type ModelBenchmarkMeasurement = {
|
|
4
|
+
sourceModelId: string;
|
|
5
|
+
reasoningEffort: ReasoningEffort | null;
|
|
6
|
+
rating: number;
|
|
7
|
+
ratingLower: number;
|
|
8
|
+
ratingUpper: number;
|
|
9
|
+
};
|
|
10
|
+
export declare const MODEL_BENCHMARK_AVAILABILITIES: readonly ["available", "provider_unconfigured"];
|
|
11
|
+
export type ModelBenchmarkAvailability = (typeof MODEL_BENCHMARK_AVAILABILITIES)[number];
|
|
12
|
+
/** One offered route with its measured variants and list price. */
|
|
13
|
+
export type BenchmarkModelOption = {
|
|
14
|
+
availability: ModelBenchmarkAvailability;
|
|
15
|
+
costPerTypicalCallUsd: number | null;
|
|
16
|
+
measurements: readonly ModelBenchmarkMeasurement[];
|
|
17
|
+
/** Brand of the model's creator; differs from `provider` for aggregators. */
|
|
18
|
+
iconProvider: BYOKProvider;
|
|
19
|
+
provider: BYOKProvider;
|
|
20
|
+
value: string;
|
|
21
|
+
};
|
|
22
|
+
export type ModelBenchmarkPoint = {
|
|
23
|
+
availability: ModelBenchmarkAvailability;
|
|
24
|
+
costPerTypicalCallUsd: number;
|
|
25
|
+
id: string;
|
|
26
|
+
isDirectRoute: boolean;
|
|
27
|
+
modelValue: string;
|
|
28
|
+
reasoningEffort: ReasoningEffort | null;
|
|
29
|
+
rating: number;
|
|
30
|
+
ratingLower: number;
|
|
31
|
+
ratingUpper: number;
|
|
32
|
+
sourceModelId: string;
|
|
33
|
+
};
|
|
34
|
+
export declare const buildModelBenchmarkPoints: (options: readonly BenchmarkModelOption[]) => ModelBenchmarkPoint[];
|
|
35
|
+
/**
|
|
36
|
+
* One point per Arena row: several routes (first-party, aggregator) can serve
|
|
37
|
+
* the same measured variant. Prefer a route the organization can use, then
|
|
38
|
+
* the model creator's own API, then the lexically first id for determinism.
|
|
39
|
+
*/
|
|
40
|
+
export declare const getUniqueModelBenchmarkPoints: <TPoint extends ModelBenchmarkPoint>(points: readonly TPoint[]) => TPoint[];
|
|
41
|
+
/** Pareto dominance on point estimates: no costlier and no worse, one strictly. */
|
|
42
|
+
export declare const dominatesBenchmarkPoint: (candidate: ModelBenchmarkPoint, target: ModelBenchmarkPoint) => boolean;
|
|
43
|
+
/** No costlier, and better beyond both confidence intervals. */
|
|
44
|
+
export declare const statisticallyDominatesBenchmarkPoint: (candidate: ModelBenchmarkPoint, target: ModelBenchmarkPoint) => boolean;
|
|
45
|
+
/** Non-dominated points, ordered by cost then rating. */
|
|
46
|
+
export declare const getParetoFrontier: <TPoint extends ModelBenchmarkPoint>(points: readonly TPoint[]) => TPoint[];
|
|
47
|
+
export declare const MODEL_BENCHMARK_CLASSIFICATIONS: readonly ["frontier", "near_frontier", "dominated"];
|
|
48
|
+
export type ModelBenchmarkClassification = (typeof MODEL_BENCHMARK_CLASSIFICATIONS)[number];
|
|
49
|
+
/**
|
|
50
|
+
* Frontier: not dominated on point estimates. Dominated: some point is no
|
|
51
|
+
* costlier and its lower bound clears this point's upper bound. Everything
|
|
52
|
+
* else is within uncertainty of the frontier.
|
|
53
|
+
*/
|
|
54
|
+
export declare const classifyBenchmarkPoints: (points: readonly ModelBenchmarkPoint[]) => ReadonlyMap<string, ModelBenchmarkClassification>;
|
|
55
|
+
export declare const PREMIUM_COST_MULTIPLIER = 3;
|
|
56
|
+
/** Points costing at least three times the median cost per typical call. */
|
|
57
|
+
export declare const getPremiumBenchmarkPointIds: (points: readonly ModelBenchmarkPoint[]) => ReadonlySet<string>;
|
|
58
|
+
export type ClassifiedBenchmarkMeasurement = ModelBenchmarkMeasurement & {
|
|
59
|
+
classification: ModelBenchmarkClassification;
|
|
60
|
+
premium: boolean;
|
|
61
|
+
};
|
|
62
|
+
export type ModelBenchmarkTradeoff = {
|
|
63
|
+
dominatedReasoningEfforts: readonly (ReasoningEffort | null)[];
|
|
64
|
+
premiumReasoningEfforts: readonly (ReasoningEffort | null)[];
|
|
65
|
+
type: "dominated" | "near_frontier" | "pareto" | "unmeasured";
|
|
66
|
+
};
|
|
67
|
+
export type ClassifiedBenchmarkModelOption<TOption extends BenchmarkModelOption> = Omit<TOption, "measurements"> & {
|
|
68
|
+
measurements: ClassifiedBenchmarkMeasurement[];
|
|
69
|
+
tradeoff: ModelBenchmarkTradeoff;
|
|
70
|
+
};
|
|
71
|
+
export declare const getModelBenchmarkTradeoff: (measurements: readonly ClassifiedBenchmarkMeasurement[]) => ModelBenchmarkTradeoff;
|
|
72
|
+
/**
|
|
73
|
+
* Classify every measured variant once over the whole deduplicated set, then
|
|
74
|
+
* project the result back onto each route. A route that shares an Arena row
|
|
75
|
+
* with the preferred route inherits that row's classification.
|
|
76
|
+
*/
|
|
77
|
+
export declare const classifyBenchmarkModelOptions: <TOption extends BenchmarkModelOption>(options: readonly TOption[]) => ClassifiedBenchmarkModelOption<TOption>[];
|
|
78
|
+
//#endregion
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
//#region src/benchmark-frontier.ts
|
|
2
|
+
const MODEL_BENCHMARK_AVAILABILITIES = ["available", "provider_unconfigured"];
|
|
3
|
+
const buildModelBenchmarkPoints = (options) => options.flatMap((option) => {
|
|
4
|
+
const cost = option.costPerTypicalCallUsd;
|
|
5
|
+
if (cost === null) return [];
|
|
6
|
+
return option.measurements.map((measurement) => ({
|
|
7
|
+
availability: option.availability,
|
|
8
|
+
costPerTypicalCallUsd: cost,
|
|
9
|
+
id: `${option.value}::${measurement.sourceModelId}`,
|
|
10
|
+
isDirectRoute: option.provider === option.iconProvider,
|
|
11
|
+
modelValue: option.value,
|
|
12
|
+
reasoningEffort: measurement.reasoningEffort,
|
|
13
|
+
rating: measurement.rating,
|
|
14
|
+
ratingLower: measurement.ratingLower,
|
|
15
|
+
ratingUpper: measurement.ratingUpper,
|
|
16
|
+
sourceModelId: measurement.sourceModelId
|
|
17
|
+
}));
|
|
18
|
+
});
|
|
19
|
+
const AVAILABILITY_PREFERENCE = {
|
|
20
|
+
available: 2,
|
|
21
|
+
provider_unconfigured: 0
|
|
22
|
+
};
|
|
23
|
+
const pointPreference = (point) => AVAILABILITY_PREFERENCE[point.availability] + (point.isDirectRoute ? 1 : 0);
|
|
24
|
+
/**
|
|
25
|
+
* One point per Arena row: several routes (first-party, aggregator) can serve
|
|
26
|
+
* the same measured variant. Prefer a route the organization can use, then
|
|
27
|
+
* the model creator's own API, then the lexically first id for determinism.
|
|
28
|
+
*/
|
|
29
|
+
const getUniqueModelBenchmarkPoints = (points) => {
|
|
30
|
+
const unique = /* @__PURE__ */ new Map();
|
|
31
|
+
for (const point of points) {
|
|
32
|
+
const existing = unique.get(point.sourceModelId);
|
|
33
|
+
if (existing === void 0) {
|
|
34
|
+
unique.set(point.sourceModelId, point);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const preference = pointPreference(point) - pointPreference(existing);
|
|
38
|
+
if (preference > 0 || preference === 0 && point.id < existing.id) unique.set(point.sourceModelId, point);
|
|
39
|
+
}
|
|
40
|
+
return [...unique.values()];
|
|
41
|
+
};
|
|
42
|
+
/** Pareto dominance on point estimates: no costlier and no worse, one strictly. */
|
|
43
|
+
const dominatesBenchmarkPoint = (candidate, target) => candidate.costPerTypicalCallUsd <= target.costPerTypicalCallUsd && candidate.rating >= target.rating && (candidate.costPerTypicalCallUsd < target.costPerTypicalCallUsd || candidate.rating > target.rating);
|
|
44
|
+
/** No costlier, and better beyond both confidence intervals. */
|
|
45
|
+
const statisticallyDominatesBenchmarkPoint = (candidate, target) => candidate.costPerTypicalCallUsd <= target.costPerTypicalCallUsd && candidate.ratingLower > target.ratingUpper;
|
|
46
|
+
const compareIds = (left, right) => {
|
|
47
|
+
if (left === right) return 0;
|
|
48
|
+
return left < right ? -1 : 1;
|
|
49
|
+
};
|
|
50
|
+
/** Non-dominated points, ordered by cost then rating. */
|
|
51
|
+
const getParetoFrontier = (points) => points.filter((point) => !points.some((candidate) => dominatesBenchmarkPoint(candidate, point))).toSorted((left, right) => left.costPerTypicalCallUsd - right.costPerTypicalCallUsd || left.rating - right.rating || compareIds(left.id, right.id));
|
|
52
|
+
const MODEL_BENCHMARK_CLASSIFICATIONS = [
|
|
53
|
+
"frontier",
|
|
54
|
+
"near_frontier",
|
|
55
|
+
"dominated"
|
|
56
|
+
];
|
|
57
|
+
/**
|
|
58
|
+
* Frontier: not dominated on point estimates. Dominated: some point is no
|
|
59
|
+
* costlier and its lower bound clears this point's upper bound. Everything
|
|
60
|
+
* else is within uncertainty of the frontier.
|
|
61
|
+
*/
|
|
62
|
+
const classifyBenchmarkPoints = (points) => {
|
|
63
|
+
const frontierIds = new Set(getParetoFrontier(points).map(({ id }) => id));
|
|
64
|
+
const classifications = /* @__PURE__ */ new Map();
|
|
65
|
+
for (const point of points) {
|
|
66
|
+
if (frontierIds.has(point.id)) {
|
|
67
|
+
classifications.set(point.id, "frontier");
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
classifications.set(point.id, points.some((candidate) => statisticallyDominatesBenchmarkPoint(candidate, point)) ? "dominated" : "near_frontier");
|
|
71
|
+
}
|
|
72
|
+
return classifications;
|
|
73
|
+
};
|
|
74
|
+
const PREMIUM_COST_MULTIPLIER = 3;
|
|
75
|
+
/** Points costing at least three times the median cost per typical call. */
|
|
76
|
+
const getPremiumBenchmarkPointIds = (points) => {
|
|
77
|
+
const costs = points.map(({ costPerTypicalCallUsd }) => costPerTypicalCallUsd).toSorted((left, right) => left - right);
|
|
78
|
+
const middle = Math.floor(costs.length / 2);
|
|
79
|
+
const upperMiddle = costs.at(middle);
|
|
80
|
+
if (upperMiddle === void 0) return /* @__PURE__ */ new Set();
|
|
81
|
+
const threshold = (costs.length % 2 === 0 ? ((costs.at(middle - 1) ?? upperMiddle) + upperMiddle) / 2 : upperMiddle) * 3;
|
|
82
|
+
return new Set(points.filter(({ costPerTypicalCallUsd }) => costPerTypicalCallUsd >= threshold).map(({ id }) => id));
|
|
83
|
+
};
|
|
84
|
+
const tradeoffType = (measurements) => {
|
|
85
|
+
if (measurements.length === 0) return "unmeasured";
|
|
86
|
+
const classifications = new Set(measurements.map(({ classification }) => classification));
|
|
87
|
+
if (classifications.has("frontier")) return "pareto";
|
|
88
|
+
if (classifications.has("near_frontier")) return "near_frontier";
|
|
89
|
+
return "dominated";
|
|
90
|
+
};
|
|
91
|
+
const getModelBenchmarkTradeoff = (measurements) => ({
|
|
92
|
+
dominatedReasoningEfforts: measurements.filter(({ classification }) => classification === "dominated").map(({ reasoningEffort }) => reasoningEffort),
|
|
93
|
+
premiumReasoningEfforts: measurements.filter(({ premium }) => premium).map(({ reasoningEffort }) => reasoningEffort),
|
|
94
|
+
type: tradeoffType(measurements)
|
|
95
|
+
});
|
|
96
|
+
/**
|
|
97
|
+
* Classify every measured variant once over the whole deduplicated set, then
|
|
98
|
+
* project the result back onto each route. A route that shares an Arena row
|
|
99
|
+
* with the preferred route inherits that row's classification.
|
|
100
|
+
*/
|
|
101
|
+
const classifyBenchmarkModelOptions = (options) => {
|
|
102
|
+
const points = getUniqueModelBenchmarkPoints(buildModelBenchmarkPoints(options));
|
|
103
|
+
const classifications = classifyBenchmarkPoints(points);
|
|
104
|
+
const premiumIds = getPremiumBenchmarkPointIds(points);
|
|
105
|
+
const bySourceModelId = new Map(points.map((point) => [point.sourceModelId, point]));
|
|
106
|
+
return options.map((option) => {
|
|
107
|
+
const measurements = option.measurements.flatMap((measurement) => {
|
|
108
|
+
const point = bySourceModelId.get(measurement.sourceModelId);
|
|
109
|
+
const classification = point === void 0 ? void 0 : classifications.get(point.id);
|
|
110
|
+
if (point === void 0 || classification === void 0) return [];
|
|
111
|
+
return [{
|
|
112
|
+
...measurement,
|
|
113
|
+
classification,
|
|
114
|
+
premium: premiumIds.has(point.id)
|
|
115
|
+
}];
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
...option,
|
|
119
|
+
measurements,
|
|
120
|
+
tradeoff: getModelBenchmarkTradeoff(measurements)
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
//#endregion
|
|
125
|
+
export { MODEL_BENCHMARK_AVAILABILITIES, MODEL_BENCHMARK_CLASSIFICATIONS, PREMIUM_COST_MULTIPLIER, buildModelBenchmarkPoints, classifyBenchmarkModelOptions, classifyBenchmarkPoints, dominatesBenchmarkPoint, getModelBenchmarkTradeoff, getParetoFrontier, getPremiumBenchmarkPointIds, getUniqueModelBenchmarkPoints, statisticallyDominatesBenchmarkPoint };
|