tryaii-dre 0.2.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/LICENSE +190 -0
- package/README.md +234 -0
- package/dist/banner.d.ts +24 -0
- package/dist/banner.d.ts.map +1 -0
- package/dist/banner.js +125 -0
- package/dist/banner.js.map +1 -0
- package/dist/benchmarks/index.d.ts +4 -0
- package/dist/benchmarks/index.d.ts.map +1 -0
- package/dist/benchmarks/index.js +3 -0
- package/dist/benchmarks/index.js.map +1 -0
- package/dist/benchmarks/registry.d.ts +69 -0
- package/dist/benchmarks/registry.d.ts.map +1 -0
- package/dist/benchmarks/registry.js +128 -0
- package/dist/benchmarks/registry.js.map +1 -0
- package/dist/benchmarks/standard.d.ts +6 -0
- package/dist/benchmarks/standard.d.ts.map +1 -0
- package/dist/benchmarks/standard.js +115 -0
- package/dist/benchmarks/standard.js.map +1 -0
- package/dist/budget.d.ts +65 -0
- package/dist/budget.d.ts.map +1 -0
- package/dist/budget.js +344 -0
- package/dist/budget.js.map +1 -0
- package/dist/cache/index.d.ts +27 -0
- package/dist/cache/index.d.ts.map +1 -0
- package/dist/cache/index.js +63 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/centroids/data/centroids_all-MiniLM-L6-v2.json +1 -0
- package/dist/centroids/data/trainingQueries.json +246 -0
- package/dist/centroids/generator.d.ts +63 -0
- package/dist/centroids/generator.d.ts.map +1 -0
- package/dist/centroids/generator.js +120 -0
- package/dist/centroids/generator.js.map +1 -0
- package/dist/centroids/index.d.ts +3 -0
- package/dist/centroids/index.d.ts.map +1 -0
- package/dist/centroids/index.js +3 -0
- package/dist/centroids/index.js.map +1 -0
- package/dist/centroids/loader.d.ts +87 -0
- package/dist/centroids/loader.d.ts.map +1 -0
- package/dist/centroids/loader.js +236 -0
- package/dist/centroids/loader.js.map +1 -0
- package/dist/classifiers/base.d.ts +56 -0
- package/dist/classifiers/base.d.ts.map +1 -0
- package/dist/classifiers/base.js +42 -0
- package/dist/classifiers/base.js.map +1 -0
- package/dist/classifiers/embedding.d.ts +68 -0
- package/dist/classifiers/embedding.d.ts.map +1 -0
- package/dist/classifiers/embedding.js +0 -0
- package/dist/classifiers/embedding.js.map +1 -0
- package/dist/classifiers/hybrid.d.ts +31 -0
- package/dist/classifiers/hybrid.d.ts.map +1 -0
- package/dist/classifiers/hybrid.js +61 -0
- package/dist/classifiers/hybrid.js.map +1 -0
- package/dist/classifiers/index.d.ts +4 -0
- package/dist/classifiers/index.d.ts.map +1 -0
- package/dist/classifiers/index.js +3 -0
- package/dist/classifiers/index.js.map +1 -0
- package/dist/classifiers/keyword.d.ts +29 -0
- package/dist/classifiers/keyword.d.ts.map +1 -0
- package/dist/classifiers/keyword.js +264 -0
- package/dist/classifiers/keyword.js.map +1 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +597 -0
- package/dist/cli.js.map +1 -0
- package/dist/client-types.d.ts +101 -0
- package/dist/client-types.d.ts.map +1 -0
- package/dist/client-types.js +5 -0
- package/dist/client-types.js.map +1 -0
- package/dist/client.d.ts +50 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +279 -0
- package/dist/client.js.map +1 -0
- package/dist/config.d.ts +45 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +37 -0
- package/dist/config.js.map +1 -0
- package/dist/dashboard/index.d.ts +48 -0
- package/dist/dashboard/index.d.ts.map +1 -0
- package/dist/dashboard/index.js +166 -0
- package/dist/dashboard/index.js.map +1 -0
- package/dist/embeddings/base.d.ts +66 -0
- package/dist/embeddings/base.d.ts.map +1 -0
- package/dist/embeddings/base.js +77 -0
- package/dist/embeddings/base.js.map +1 -0
- package/dist/embeddings/index.d.ts +3 -0
- package/dist/embeddings/index.d.ts.map +1 -0
- package/dist/embeddings/index.js +3 -0
- package/dist/embeddings/index.js.map +1 -0
- package/dist/embeddings/local.d.ts +42 -0
- package/dist/embeddings/local.d.ts.map +1 -0
- package/dist/embeddings/local.js +89 -0
- package/dist/embeddings/local.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/index.d.ts +3 -0
- package/dist/integrations/index.d.ts.map +1 -0
- package/dist/integrations/index.js +2 -0
- package/dist/integrations/index.js.map +1 -0
- package/dist/integrations/openrouter.d.ts +84 -0
- package/dist/integrations/openrouter.d.ts.map +1 -0
- package/dist/integrations/openrouter.js +253 -0
- package/dist/integrations/openrouter.js.map +1 -0
- package/dist/registry/index.d.ts +2 -0
- package/dist/registry/index.d.ts.map +1 -0
- package/dist/registry/index.js +2 -0
- package/dist/registry/index.js.map +1 -0
- package/dist/registry/models.d.ts +76 -0
- package/dist/registry/models.d.ts.map +1 -0
- package/dist/registry/models.js +170 -0
- package/dist/registry/models.js.map +1 -0
- package/dist/registry/presets/defaultModels.json +435 -0
- package/dist/router.d.ts +178 -0
- package/dist/router.d.ts.map +1 -0
- package/dist/router.js +259 -0
- package/dist/router.js.map +1 -0
- package/dist/scoring/benchmarks.d.ts +35 -0
- package/dist/scoring/benchmarks.d.ts.map +1 -0
- package/dist/scoring/benchmarks.js +68 -0
- package/dist/scoring/benchmarks.js.map +1 -0
- package/dist/scoring/engine.d.ts +43 -0
- package/dist/scoring/engine.d.ts.map +1 -0
- package/dist/scoring/engine.js +267 -0
- package/dist/scoring/engine.js.map +1 -0
- package/dist/scoring/index.d.ts +6 -0
- package/dist/scoring/index.d.ts.map +1 -0
- package/dist/scoring/index.js +4 -0
- package/dist/scoring/index.js.map +1 -0
- package/dist/scoring/priorities.d.ts +41 -0
- package/dist/scoring/priorities.d.ts.map +1 -0
- package/dist/scoring/priorities.js +49 -0
- package/dist/scoring/priorities.js.map +1 -0
- package/dist/types.d.ts +47 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/cosine.d.ts +10 -0
- package/dist/utils/cosine.d.ts.map +1 -0
- package/dist/utils/cosine.js +18 -0
- package/dist/utils/cosine.js.map +1 -0
- package/dist/utils/math.d.ts +18 -0
- package/dist/utils/math.d.ts.map +1 -0
- package/dist/utils/math.js +54 -0
- package/dist/utils/math.js.map +1 -0
- package/package.json +65 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-contained HTML dashboard for an eval run.
|
|
3
|
+
*
|
|
4
|
+
* Reads the same shape that gets written to `summary.json`, so it can be used
|
|
5
|
+
* both at the end of a live run and as a backfill over existing runs.
|
|
6
|
+
*/
|
|
7
|
+
function esc(s) {
|
|
8
|
+
return s.replace(/[&<>"']/g, (c) => c === '&' ? '&' : c === '<' ? '<' : c === '>' ? '>' : c === '"' ? '"' : ''');
|
|
9
|
+
}
|
|
10
|
+
export function renderDashboard(summary, inputPath, links = {}) {
|
|
11
|
+
const generatedAt = new Date().toISOString();
|
|
12
|
+
const { quality, cost, speed } = summary.priorities;
|
|
13
|
+
const summaryHref = links.summaryHref ?? 'summary.json';
|
|
14
|
+
const resultsHref = links.resultsHref ?? 'results.jsonl';
|
|
15
|
+
const priorityChip = (label, value) => `<span class="chip chip-p${value}">${label} <b>${value}</b></span>`;
|
|
16
|
+
const distRows = summary.distribution
|
|
17
|
+
.map((row) => `
|
|
18
|
+
<li class="row">
|
|
19
|
+
<span class="row-label" title="${esc(row.model)}">${esc(row.model)}</span>
|
|
20
|
+
<span class="row-bar"><span class="row-bar-fill" style="width:${row.pct}%"></span></span>
|
|
21
|
+
<span class="row-num">${row.count}</span>
|
|
22
|
+
<span class="row-pct">${row.pct}%</span>
|
|
23
|
+
</li>`)
|
|
24
|
+
.join('');
|
|
25
|
+
const categoryCards = summary.byCategory
|
|
26
|
+
.map((cat) => {
|
|
27
|
+
const models = cat.topModels
|
|
28
|
+
.slice(0, 3)
|
|
29
|
+
.map((m) => `
|
|
30
|
+
<li class="row">
|
|
31
|
+
<span class="row-label" title="${esc(m.model)}">${esc(m.model)}</span>
|
|
32
|
+
<span class="row-bar"><span class="row-bar-fill" style="width:${m.pct}%"></span></span>
|
|
33
|
+
<span class="row-pct">${m.pct}%</span>
|
|
34
|
+
</li>`)
|
|
35
|
+
.join('');
|
|
36
|
+
const benches = cat.topBenchmarks
|
|
37
|
+
.slice(0, 5)
|
|
38
|
+
.map((b) => `<li><span>${esc(b.name)}</span><b>${b.avgScore.toFixed(3)}</b></li>`)
|
|
39
|
+
.join('');
|
|
40
|
+
return `
|
|
41
|
+
<article class="card">
|
|
42
|
+
<header class="card-head">
|
|
43
|
+
<h3>${esc(cat.category)}</h3>
|
|
44
|
+
<span class="muted">${cat.count} prompts</span>
|
|
45
|
+
</header>
|
|
46
|
+
<h4 class="card-sub">Top models</h4>
|
|
47
|
+
<ul class="rows">${models}</ul>
|
|
48
|
+
${benches ? `<h4 class="card-sub">Top benchmarks</h4><ul class="benches">${benches}</ul>` : ''}
|
|
49
|
+
</article>`;
|
|
50
|
+
})
|
|
51
|
+
.join('');
|
|
52
|
+
return `<!doctype html>
|
|
53
|
+
<html lang="en">
|
|
54
|
+
<head>
|
|
55
|
+
<meta charset="utf-8">
|
|
56
|
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
|
57
|
+
<title>tryaii-dre eval — ${summary.totalPrompts} prompts</title>
|
|
58
|
+
<style>
|
|
59
|
+
:root {
|
|
60
|
+
--bg: #0b0d10;
|
|
61
|
+
--panel: #14181d;
|
|
62
|
+
--panel-2: #1b2026;
|
|
63
|
+
--text: #e6e9ee;
|
|
64
|
+
--muted: #8a939d;
|
|
65
|
+
--line: #232932;
|
|
66
|
+
--accent: #6ee7b7;
|
|
67
|
+
--accent-2: #93c5fd;
|
|
68
|
+
--warn: #fcd34d;
|
|
69
|
+
}
|
|
70
|
+
@media (prefers-color-scheme: light) {
|
|
71
|
+
:root { --bg:#fafbfc; --panel:#ffffff; --panel-2:#f4f6f9; --text:#0f1419; --muted:#5b6470; --line:#e6eaef; --accent:#059669; --accent-2:#2563eb; --warn:#b45309; }
|
|
72
|
+
}
|
|
73
|
+
* { box-sizing: border-box; }
|
|
74
|
+
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
|
|
75
|
+
font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
|
|
76
|
+
main { max-width: 1100px; margin: 0 auto; padding: 32px 24px 64px; }
|
|
77
|
+
header.top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
|
|
78
|
+
header.top h1 { font-size: 18px; margin: 0; font-weight: 600; letter-spacing: 0.2px; }
|
|
79
|
+
header.top h1 small { color: var(--muted); font-weight: 400; margin-left: 8px; }
|
|
80
|
+
.meta { color: var(--muted); font-size: 12px; }
|
|
81
|
+
.chips { display: flex; gap: 8px; margin: 16px 0 28px; flex-wrap: wrap; }
|
|
82
|
+
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px;
|
|
83
|
+
background: var(--panel-2); border: 1px solid var(--line); font-size: 12px; color: var(--muted); }
|
|
84
|
+
.chip b { color: var(--text); font-weight: 600; }
|
|
85
|
+
.chip-p5 b { color: var(--accent); }
|
|
86
|
+
.chip-p4 b { color: var(--accent-2); }
|
|
87
|
+
.chip-p1 b, .chip-p2 b { color: var(--muted); }
|
|
88
|
+
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 28px; }
|
|
89
|
+
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
|
|
90
|
+
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
|
|
91
|
+
.stat .v { font-size: 22px; font-weight: 600; margin-top: 4px; }
|
|
92
|
+
.stat .v.warn { color: var(--warn); }
|
|
93
|
+
section { margin-bottom: 32px; }
|
|
94
|
+
section > h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted);
|
|
95
|
+
font-weight: 600; margin: 0 0 12px; }
|
|
96
|
+
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px; }
|
|
97
|
+
ul.rows { list-style: none; margin: 0; padding: 0; }
|
|
98
|
+
ul.rows .row { display: grid; grid-template-columns: 1fr 2fr auto auto; gap: 12px; align-items: center;
|
|
99
|
+
padding: 6px 0; border-bottom: 1px dashed var(--line); }
|
|
100
|
+
ul.rows .row:last-child { border-bottom: 0; }
|
|
101
|
+
.row-label { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px;
|
|
102
|
+
overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
103
|
+
.row-bar { background: var(--panel-2); border-radius: 4px; height: 8px; overflow: hidden; }
|
|
104
|
+
.row-bar-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
|
|
105
|
+
.row-num { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 40px; text-align: right; }
|
|
106
|
+
.row-pct { color: var(--text); font-variant-numeric: tabular-nums; min-width: 56px; text-align: right; font-weight: 500; }
|
|
107
|
+
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
|
|
108
|
+
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
|
|
109
|
+
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
|
|
110
|
+
.card-head h3 { font-size: 14px; margin: 0; font-weight: 600; text-transform: capitalize; }
|
|
111
|
+
.card-sub { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted);
|
|
112
|
+
margin: 12px 0 6px; font-weight: 600; }
|
|
113
|
+
.card .rows .row { grid-template-columns: 1fr 2fr auto; }
|
|
114
|
+
ul.benches { list-style: none; margin: 0; padding: 0; }
|
|
115
|
+
ul.benches li { display: flex; justify-content: space-between; padding: 3px 0; font-size: 12px;
|
|
116
|
+
color: var(--muted); }
|
|
117
|
+
ul.benches b { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 500; }
|
|
118
|
+
.muted { color: var(--muted); font-size: 12px; }
|
|
119
|
+
footer { color: var(--muted); font-size: 12px; margin-top: 32px; display: flex; gap: 16px; flex-wrap: wrap; }
|
|
120
|
+
footer a { color: var(--accent-2); text-decoration: none; }
|
|
121
|
+
footer a:hover { text-decoration: underline; }
|
|
122
|
+
@media (max-width: 720px) { .stats { grid-template-columns: repeat(2, 1fr); } }
|
|
123
|
+
</style>
|
|
124
|
+
</head>
|
|
125
|
+
<body>
|
|
126
|
+
<main>
|
|
127
|
+
<header class="top">
|
|
128
|
+
<h1>tryaii-dre routing eval <small>${summary.totalPrompts} prompts</small></h1>
|
|
129
|
+
<span class="meta">${esc(generatedAt)}</span>
|
|
130
|
+
</header>
|
|
131
|
+
<div class="meta">input: <code>${esc(inputPath)}</code></div>
|
|
132
|
+
|
|
133
|
+
<div class="chips">
|
|
134
|
+
${priorityChip('quality', quality)}
|
|
135
|
+
${priorityChip('cost', cost)}
|
|
136
|
+
${priorityChip('speed', speed)}
|
|
137
|
+
</div>
|
|
138
|
+
|
|
139
|
+
<div class="stats">
|
|
140
|
+
<div class="stat"><div class="k">Successes</div><div class="v">${summary.successCount}</div></div>
|
|
141
|
+
<div class="stat"><div class="k">Errors</div><div class="v${summary.errorCount > 0 ? ' warn' : ''}">${summary.errorCount}</div></div>
|
|
142
|
+
<div class="stat"><div class="k">Distinct models</div><div class="v">${summary.distinctModels}</div></div>
|
|
143
|
+
<div class="stat"><div class="k">Avg route</div><div class="v">${summary.avgRouteMs} <span class="muted" style="font-size:13px">ms</span></div></div>
|
|
144
|
+
</div>
|
|
145
|
+
|
|
146
|
+
<section>
|
|
147
|
+
<h2>Recommended models — overall</h2>
|
|
148
|
+
<div class="panel"><ul class="rows">${distRows}</ul></div>
|
|
149
|
+
</section>
|
|
150
|
+
|
|
151
|
+
<section>
|
|
152
|
+
<h2>By category</h2>
|
|
153
|
+
<div class="grid">${categoryCards}</div>
|
|
154
|
+
</section>
|
|
155
|
+
|
|
156
|
+
<footer>
|
|
157
|
+
<span>artifacts:</span>
|
|
158
|
+
<a href="${esc(summaryHref)}">summary.json</a>
|
|
159
|
+
<a href="${esc(resultsHref)}">results.jsonl</a>
|
|
160
|
+
</footer>
|
|
161
|
+
</main>
|
|
162
|
+
</body>
|
|
163
|
+
</html>
|
|
164
|
+
`;
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dashboard/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAmBH,SAAS,GAAG,CAAC,CAAS;IACpB,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CACjC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,OAAO,CAC/F,CAAC;AACJ,CAAC;AAYD,MAAM,UAAU,eAAe,CAC7B,OAAyB,EACzB,SAAiB,EACjB,QAAwB,EAAE;IAE1B,MAAM,WAAW,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC7C,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,UAAU,CAAC;IACpD,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,IAAI,cAAc,CAAC;IACxD,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,IAAI,eAAe,CAAC;IAEzD,MAAM,YAAY,GAAG,CAAC,KAAa,EAAE,KAAa,EAAU,EAAE,CAC5D,2BAA2B,KAAK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,CAAC,EAAE,CAAC,CAAC;IAEZ,OAAO;;;;;2BAKkB,OAAO,CAAC,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yCAuEN,OAAO,CAAC,YAAY;yBACpC,GAAG,CAAC,WAAW,CAAC;;mCAEN,GAAG,CAAC,SAAS,CAAC;;;MAG3C,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC;MAChC,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC;MAC1B,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC;;;;qEAImC,OAAO,CAAC,YAAY;gEACzB,OAAO,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,UAAU;2EACjD,OAAO,CAAC,cAAc;qEAC5B,OAAO,CAAC,UAAU;;;;;0CAK7C,QAAQ;;;;;wBAK1B,aAAa;;;;;eAKtB,GAAG,CAAC,WAAW,CAAC;eAChB,GAAG,CAAC,WAAW,CAAC;;;;;CAK9B,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract embedding provider interface.
|
|
3
|
+
*
|
|
4
|
+
* Allows swapping between local (@xenova/transformers) and cloud (OpenAI)
|
|
5
|
+
* embedding backends without changing the classifier logic.
|
|
6
|
+
*
|
|
7
|
+
* The async path (`embedAsync` / `embedBatchAsync`) is the primary contract
|
|
8
|
+
* -- every provider must implement it. Sync support is optional: providers
|
|
9
|
+
* that can produce embeddings without I/O can override `embed` / `embedBatch`
|
|
10
|
+
* and set `supportsSync` to true. Sync providers automatically support the
|
|
11
|
+
* async path through the default fallback below.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Base class for embedding providers.
|
|
15
|
+
*
|
|
16
|
+
* All providers must implement embedAsync(), embedBatchAsync(), dimension,
|
|
17
|
+
* and modelName. Sync support is optional and gated on `supportsSync`.
|
|
18
|
+
*/
|
|
19
|
+
export declare abstract class BaseEmbeddingProvider {
|
|
20
|
+
/**
|
|
21
|
+
* Generate an embedding vector for a single text (async).
|
|
22
|
+
*
|
|
23
|
+
* Default implementation wraps the sync `embed()` -- so sync providers
|
|
24
|
+
* (those that override `embed`) automatically support the async path
|
|
25
|
+
* with no extra code. Async-only providers must override this method
|
|
26
|
+
* and leave `embed()` to its default-throwing implementation.
|
|
27
|
+
*/
|
|
28
|
+
embedAsync(text: string): Promise<number[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Generate embeddings for multiple texts (async).
|
|
31
|
+
*
|
|
32
|
+
* Default implementation loops `embedAsync()` -- which routes through the
|
|
33
|
+
* provider's real async implementation for async-only providers, and
|
|
34
|
+
* through the sync-wrapping default for sync providers. Override for
|
|
35
|
+
* batch-friendly async backends that can do better than N sequential calls.
|
|
36
|
+
*/
|
|
37
|
+
embedBatchAsync(texts: string[]): Promise<number[][]>;
|
|
38
|
+
/**
|
|
39
|
+
* Generate an embedding vector synchronously.
|
|
40
|
+
*
|
|
41
|
+
* Optional. Default throws -- only providers that have set
|
|
42
|
+
* `supportsSync = true` should override this. Used by the niche
|
|
43
|
+
* `Router.routeSync()` path for callers that need a blocking API.
|
|
44
|
+
*/
|
|
45
|
+
embed(_text: string): number[];
|
|
46
|
+
/**
|
|
47
|
+
* Generate embeddings for multiple texts synchronously.
|
|
48
|
+
*
|
|
49
|
+
* Default loops `embed()`; both will throw unless the provider opted in
|
|
50
|
+
* to sync support.
|
|
51
|
+
*/
|
|
52
|
+
embedBatch(texts: string[]): number[][];
|
|
53
|
+
/**
|
|
54
|
+
* Whether this provider supports the synchronous `embed()` path.
|
|
55
|
+
*
|
|
56
|
+
* Defaults to false -- the async path is the contract every provider
|
|
57
|
+
* is required to fulfil. Providers override this getter to return true
|
|
58
|
+
* when they implement `embed()`.
|
|
59
|
+
*/
|
|
60
|
+
get supportsSync(): boolean;
|
|
61
|
+
/** Dimensionality of the embedding vectors. */
|
|
62
|
+
abstract get dimension(): number;
|
|
63
|
+
/** Name/identifier of the embedding model. */
|
|
64
|
+
abstract get modelName(): string;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/embeddings/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;GAKG;AACH,8BAAsB,qBAAqB;IACzC;;;;;;;OAOG;IACG,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAIjD;;;;;;;OAOG;IACG,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IAM3D;;;;;;OAMG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE;IAQ9B;;;;;OAKG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE;IAIvC;;;;;;OAMG;IACH,IAAI,YAAY,IAAI,OAAO,CAE1B;IAED,+CAA+C;IAC/C,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC;IAEjC,8CAA8C;IAC9C,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC;CAClC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Abstract embedding provider interface.
|
|
3
|
+
*
|
|
4
|
+
* Allows swapping between local (@xenova/transformers) and cloud (OpenAI)
|
|
5
|
+
* embedding backends without changing the classifier logic.
|
|
6
|
+
*
|
|
7
|
+
* The async path (`embedAsync` / `embedBatchAsync`) is the primary contract
|
|
8
|
+
* -- every provider must implement it. Sync support is optional: providers
|
|
9
|
+
* that can produce embeddings without I/O can override `embed` / `embedBatch`
|
|
10
|
+
* and set `supportsSync` to true. Sync providers automatically support the
|
|
11
|
+
* async path through the default fallback below.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Base class for embedding providers.
|
|
15
|
+
*
|
|
16
|
+
* All providers must implement embedAsync(), embedBatchAsync(), dimension,
|
|
17
|
+
* and modelName. Sync support is optional and gated on `supportsSync`.
|
|
18
|
+
*/
|
|
19
|
+
export class BaseEmbeddingProvider {
|
|
20
|
+
/**
|
|
21
|
+
* Generate an embedding vector for a single text (async).
|
|
22
|
+
*
|
|
23
|
+
* Default implementation wraps the sync `embed()` -- so sync providers
|
|
24
|
+
* (those that override `embed`) automatically support the async path
|
|
25
|
+
* with no extra code. Async-only providers must override this method
|
|
26
|
+
* and leave `embed()` to its default-throwing implementation.
|
|
27
|
+
*/
|
|
28
|
+
async embedAsync(text) {
|
|
29
|
+
return this.embed(text);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Generate embeddings for multiple texts (async).
|
|
33
|
+
*
|
|
34
|
+
* Default implementation loops `embedAsync()` -- which routes through the
|
|
35
|
+
* provider's real async implementation for async-only providers, and
|
|
36
|
+
* through the sync-wrapping default for sync providers. Override for
|
|
37
|
+
* batch-friendly async backends that can do better than N sequential calls.
|
|
38
|
+
*/
|
|
39
|
+
async embedBatchAsync(texts) {
|
|
40
|
+
const out = [];
|
|
41
|
+
for (const t of texts)
|
|
42
|
+
out.push(await this.embedAsync(t));
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Generate an embedding vector synchronously.
|
|
47
|
+
*
|
|
48
|
+
* Optional. Default throws -- only providers that have set
|
|
49
|
+
* `supportsSync = true` should override this. Used by the niche
|
|
50
|
+
* `Router.routeSync()` path for callers that need a blocking API.
|
|
51
|
+
*/
|
|
52
|
+
embed(_text) {
|
|
53
|
+
throw new Error(`${this.constructor.name} does not support synchronous embed(). ` +
|
|
54
|
+
'Use the async path (Router.route / embedAsync) or inject a provider ' +
|
|
55
|
+
'whose supportsSync is true.');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Generate embeddings for multiple texts synchronously.
|
|
59
|
+
*
|
|
60
|
+
* Default loops `embed()`; both will throw unless the provider opted in
|
|
61
|
+
* to sync support.
|
|
62
|
+
*/
|
|
63
|
+
embedBatch(texts) {
|
|
64
|
+
return texts.map((t) => this.embed(t));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Whether this provider supports the synchronous `embed()` path.
|
|
68
|
+
*
|
|
69
|
+
* Defaults to false -- the async path is the contract every provider
|
|
70
|
+
* is required to fulfil. Providers override this getter to return true
|
|
71
|
+
* when they implement `embed()`.
|
|
72
|
+
*/
|
|
73
|
+
get supportsSync() {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/embeddings/base.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;;GAKG;AACH,MAAM,OAAgB,qBAAqB;IACzC;;;;;;;OAOG;IACH,KAAK,CAAC,UAAU,CAAC,IAAY;QAC3B,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,eAAe,CAAC,KAAe;QACnC,MAAM,GAAG,GAAe,EAAE,CAAC;QAC3B,KAAK,MAAM,CAAC,IAAI,KAAK;YAAE,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1D,OAAO,GAAG,CAAC;IACb,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,KAAa;QACjB,MAAM,IAAI,KAAK,CACb,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,yCAAyC;YAC/D,sEAAsE;YACtE,6BAA6B,CAChC,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,UAAU,CAAC,KAAe;QACxB,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,CAAC;IAED;;;;;;OAMG;IACH,IAAI,YAAY;QACd,OAAO,KAAK,CAAC;IACf,CAAC;CAOF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/embeddings/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/embeddings/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local embedding provider using @xenova/transformers.
|
|
3
|
+
*
|
|
4
|
+
* Default model: all-MiniLM-L6-v2 (22M params, 384 dimensions)
|
|
5
|
+
* - Runs on CPU on any modern machine
|
|
6
|
+
* - No API keys needed
|
|
7
|
+
* - ~50ms per embedding on average hardware
|
|
8
|
+
*
|
|
9
|
+
* @xenova/transformers is an optional dependency -- lazy-loaded on first use.
|
|
10
|
+
*
|
|
11
|
+
* This provider is async-only. The ONNX runtime exposed by
|
|
12
|
+
* @xenova/transformers returns Promises for both pipeline construction and
|
|
13
|
+
* per-call inference, so there is no honest way to offer a sync `embed()`.
|
|
14
|
+
* Use `Router.route()` (async) with this provider; `Router.routeSync()` will
|
|
15
|
+
* reject it via `supportsSync === false`.
|
|
16
|
+
*/
|
|
17
|
+
import { BaseEmbeddingProvider } from './base.js';
|
|
18
|
+
/**
|
|
19
|
+
* Local embedding provider using @xenova/transformers (ONNX-based).
|
|
20
|
+
*
|
|
21
|
+
* Lazy-loads the model on first use to keep import times fast.
|
|
22
|
+
*
|
|
23
|
+
* @param modelName - HuggingFace model name. Default: "Xenova/all-MiniLM-L6-v2"
|
|
24
|
+
*/
|
|
25
|
+
export declare class LocalEmbeddingProvider extends BaseEmbeddingProvider {
|
|
26
|
+
private _modelName;
|
|
27
|
+
private _extractor;
|
|
28
|
+
private _dimension;
|
|
29
|
+
constructor(modelName?: string);
|
|
30
|
+
/**
|
|
31
|
+
* Internal async initializer -- called once to set up the ONNX pipeline.
|
|
32
|
+
* Returns the feature-extraction pipeline instance.
|
|
33
|
+
*/
|
|
34
|
+
private _getExtractor;
|
|
35
|
+
/** Pre-initialize the model. Optional -- the first embedAsync() call also triggers init. */
|
|
36
|
+
init(): Promise<void>;
|
|
37
|
+
embedAsync(text: string): Promise<number[]>;
|
|
38
|
+
embedBatchAsync(texts: string[]): Promise<number[][]>;
|
|
39
|
+
get dimension(): number;
|
|
40
|
+
get modelName(): string;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=local.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.d.ts","sourceRoot":"","sources":["../../src/embeddings/local.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAKlD;;;;;;GAMG;AACH,qBAAa,sBAAuB,SAAQ,qBAAqB;IAC/D,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,UAAU,CAAyB;IAC3C,OAAO,CAAC,UAAU,CAAuB;gBAE7B,SAAS,SAA4B;IAKjD;;;OAGG;YACW,aAAa;IAiC3B,4FAA4F;IACtF,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAIrB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAM3C,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC;IAQ3D,IAAI,SAAS,IAAI,MAAM,CAKtB;IAED,IAAI,SAAS,IAAI,MAAM,CAGtB;CACF"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local embedding provider using @xenova/transformers.
|
|
3
|
+
*
|
|
4
|
+
* Default model: all-MiniLM-L6-v2 (22M params, 384 dimensions)
|
|
5
|
+
* - Runs on CPU on any modern machine
|
|
6
|
+
* - No API keys needed
|
|
7
|
+
* - ~50ms per embedding on average hardware
|
|
8
|
+
*
|
|
9
|
+
* @xenova/transformers is an optional dependency -- lazy-loaded on first use.
|
|
10
|
+
*
|
|
11
|
+
* This provider is async-only. The ONNX runtime exposed by
|
|
12
|
+
* @xenova/transformers returns Promises for both pipeline construction and
|
|
13
|
+
* per-call inference, so there is no honest way to offer a sync `embed()`.
|
|
14
|
+
* Use `Router.route()` (async) with this provider; `Router.routeSync()` will
|
|
15
|
+
* reject it via `supportsSync === false`.
|
|
16
|
+
*/
|
|
17
|
+
import { BaseEmbeddingProvider } from './base.js';
|
|
18
|
+
/**
|
|
19
|
+
* Local embedding provider using @xenova/transformers (ONNX-based).
|
|
20
|
+
*
|
|
21
|
+
* Lazy-loads the model on first use to keep import times fast.
|
|
22
|
+
*
|
|
23
|
+
* @param modelName - HuggingFace model name. Default: "Xenova/all-MiniLM-L6-v2"
|
|
24
|
+
*/
|
|
25
|
+
export class LocalEmbeddingProvider extends BaseEmbeddingProvider {
|
|
26
|
+
constructor(modelName = 'Xenova/all-MiniLM-L6-v2') {
|
|
27
|
+
super();
|
|
28
|
+
this._extractor = null;
|
|
29
|
+
this._dimension = null;
|
|
30
|
+
this._modelName = modelName;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Internal async initializer -- called once to set up the ONNX pipeline.
|
|
34
|
+
* Returns the feature-extraction pipeline instance.
|
|
35
|
+
*/
|
|
36
|
+
async _getExtractor() {
|
|
37
|
+
if (this._extractor !== null) {
|
|
38
|
+
return this._extractor;
|
|
39
|
+
}
|
|
40
|
+
let pipelineFn;
|
|
41
|
+
try {
|
|
42
|
+
const mod = await import('@xenova/transformers');
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
pipelineFn = mod.pipeline ?? mod.default?.pipeline;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
throw new Error('@xenova/transformers is required for local embeddings. ' +
|
|
48
|
+
'Install it with: npm install @xenova/transformers');
|
|
49
|
+
}
|
|
50
|
+
if (!pipelineFn) {
|
|
51
|
+
throw new Error('Could not find pipeline export in @xenova/transformers');
|
|
52
|
+
}
|
|
53
|
+
const extractor = await pipelineFn('feature-extraction', this._modelName, {
|
|
54
|
+
quantized: true,
|
|
55
|
+
});
|
|
56
|
+
// Determine dimension from a test embedding
|
|
57
|
+
const testOutput = await extractor('test', { pooling: 'mean', normalize: true });
|
|
58
|
+
this._dimension = testOutput.dims[testOutput.dims.length - 1];
|
|
59
|
+
this._extractor = extractor;
|
|
60
|
+
return extractor;
|
|
61
|
+
}
|
|
62
|
+
/** Pre-initialize the model. Optional -- the first embedAsync() call also triggers init. */
|
|
63
|
+
async init() {
|
|
64
|
+
await this._getExtractor();
|
|
65
|
+
}
|
|
66
|
+
async embedAsync(text) {
|
|
67
|
+
const extractor = await this._getExtractor();
|
|
68
|
+
const output = await extractor(text, { pooling: 'mean', normalize: true });
|
|
69
|
+
return Array.from(output.data);
|
|
70
|
+
}
|
|
71
|
+
async embedBatchAsync(texts) {
|
|
72
|
+
const results = [];
|
|
73
|
+
for (const text of texts) {
|
|
74
|
+
results.push(await this.embedAsync(text));
|
|
75
|
+
}
|
|
76
|
+
return results;
|
|
77
|
+
}
|
|
78
|
+
get dimension() {
|
|
79
|
+
if (this._dimension === null) {
|
|
80
|
+
return 384; // Default for all-MiniLM-L6-v2
|
|
81
|
+
}
|
|
82
|
+
return this._dimension;
|
|
83
|
+
}
|
|
84
|
+
get modelName() {
|
|
85
|
+
// Return short name (without Xenova/ prefix) for compatibility with centroid files
|
|
86
|
+
return this._modelName.replace('Xenova/', '');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=local.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local.js","sourceRoot":"","sources":["../../src/embeddings/local.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAKlD;;;;;;GAMG;AACH,MAAM,OAAO,sBAAuB,SAAQ,qBAAqB;IAK/D,YAAY,SAAS,GAAG,yBAAyB;QAC/C,KAAK,EAAE,CAAC;QAJF,eAAU,GAAoB,IAAI,CAAC;QACnC,eAAU,GAAkB,IAAI,CAAC;QAIvC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACK,KAAK,CAAC,aAAa;QACzB,IAAI,IAAI,CAAC,UAAU,KAAK,IAAI,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC,UAAU,CAAC;QACzB,CAAC;QAED,IAAI,UAAoB,CAAC;QACzB,IAAI,CAAC;YACH,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,sBAAsB,CAAC,CAAC;YACjD,8DAA8D;YAC9D,UAAU,GAAG,GAAG,CAAC,QAAQ,IAAK,GAAW,CAAC,OAAO,EAAE,QAAQ,CAAC;QAC9D,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,IAAI,KAAK,CACb,yDAAyD;gBACvD,mDAAmD,CACtD,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,UAAU,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QAC5E,CAAC;QAED,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,oBAAoB,EAAE,IAAI,CAAC,UAAU,EAAE;YACxE,SAAS,EAAE,IAAI;SAChB,CAAC,CAAC;QAEH,4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,CAAC;IAChD,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TryAii-DRE -- Embedding-based AI Model Router
|
|
3
|
+
*
|
|
4
|
+
* Understands your prompt semantically and routes to the best model
|
|
5
|
+
* based on benchmarks, cost, speed, and quality priorities.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { Router } from 'tryaii-dre';
|
|
9
|
+
*
|
|
10
|
+
* const router = new Router();
|
|
11
|
+
* const result = await router.route('Write a Python function to merge sorted arrays');
|
|
12
|
+
* console.log(result.bestModel);
|
|
13
|
+
* console.log(result.scores);
|
|
14
|
+
*/
|
|
15
|
+
export { Router, routeResultTopK, routeResultBestScore, routeResultBestReasoning } from './router.js';
|
|
16
|
+
export type { RouteResult, RouteOptions } from './router.js';
|
|
17
|
+
export { DREClient } from './client.js';
|
|
18
|
+
export type { ChatOptions, ChatResponse, DREClientOptions, ModelScore as ClientModelScore, Priorities as ClientPriorities, RouteOptions as ClientRouteOptions, RouteResult as ClientRouteResult, TokenUsage, } from './client-types.js';
|
|
19
|
+
export { OpenRouterIntegration, MODEL_ID_TO_OPENROUTER } from './integrations/index.js';
|
|
20
|
+
export type { OpenRouterResponse, OpenRouterChatOptions } from './integrations/index.js';
|
|
21
|
+
export { createDefaultConfig, DEFAULT_DATA_DIR, DEFAULT_EMBEDDING_MODEL } from './config.js';
|
|
22
|
+
export type { TryaiiDreConfig, CacheConfig } from './config.js';
|
|
23
|
+
export { ModelRegistry, ModelInfo, ModelPricing } from './registry/index.js';
|
|
24
|
+
export { ScoringEngine, SPEED_SCORES } from './scoring/engine.js';
|
|
25
|
+
export type { ModelScore } from './scoring/engine.js';
|
|
26
|
+
export { Priorities, DEFAULT_PRIORITIES } from './scoring/priorities.js';
|
|
27
|
+
export type { PrioritiesData } from './scoring/priorities.js';
|
|
28
|
+
export { BenchmarkNormalizer, NormalizationRange, NORMALIZATION_RANGES } from './scoring/benchmarks.js';
|
|
29
|
+
export { BaseClassifier, emptyClassificationResult, topBenchmarks } from './classifiers/base.js';
|
|
30
|
+
export type { ClassificationResult } from './classifiers/base.js';
|
|
31
|
+
export { EmbeddingClassifier } from './classifiers/embedding.js';
|
|
32
|
+
export { BaseEmbeddingProvider } from './embeddings/base.js';
|
|
33
|
+
export { LocalEmbeddingProvider } from './embeddings/local.js';
|
|
34
|
+
export { CentroidGenerator } from './centroids/generator.js';
|
|
35
|
+
export { CentroidLoader } from './centroids/loader.js';
|
|
36
|
+
export { BenchmarkRegistry } from './benchmarks/registry.js';
|
|
37
|
+
export type { BenchmarkDefinition } from './benchmarks/registry.js';
|
|
38
|
+
export { STANDARD_BENCHMARKS } from './benchmarks/standard.js';
|
|
39
|
+
export type { LatencyTier, ScoringStrategy, ModelData, ModelsJson, CentroidsJson, TrainingQueriesJson } from './types.js';
|
|
40
|
+
export { renderDashboard } from './dashboard/index.js';
|
|
41
|
+
export type { DashboardSummary, DashboardLinks } from './dashboard/index.js';
|
|
42
|
+
export { costUnitForBudget, estimateGenerationCost, estimateTokens, optimizeBudgetCandidates, paretoPrune, routeDatasetWithBudget, } from './budget.js';
|
|
43
|
+
export type { BudgetCandidate, BudgetedRouteResult, BudgetMode, BudgetOptimizationResult, RouteDatasetWithBudgetOptions, } from './budget.js';
|
|
44
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AACtG,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG7D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,YAAY,EACV,WAAW,EACX,YAAY,EACZ,gBAAgB,EACh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B,EAAE,MAAM,0BAA0B,CAAC;AAC7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAG/D,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,SAAS,EAAE,UAAU,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAG1H,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG7E,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,EACd,wBAAwB,EACxB,WAAW,EACX,sBAAsB,GACvB,MAAM,aAAa,CAAC;AACrB,YAAY,EACV,eAAe,EACf,mBAAmB,EACnB,UAAU,EACV,wBAAwB,EACxB,6BAA6B,GAC9B,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TryAii-DRE -- Embedding-based AI Model Router
|
|
3
|
+
*
|
|
4
|
+
* Understands your prompt semantically and routes to the best model
|
|
5
|
+
* based on benchmarks, cost, speed, and quality priorities.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* import { Router } from 'tryaii-dre';
|
|
9
|
+
*
|
|
10
|
+
* const router = new Router();
|
|
11
|
+
* const result = await router.route('Write a Python function to merge sorted arrays');
|
|
12
|
+
* console.log(result.bestModel);
|
|
13
|
+
* console.log(result.scores);
|
|
14
|
+
*/
|
|
15
|
+
// Core router
|
|
16
|
+
export { Router, routeResultTopK, routeResultBestScore, routeResultBestReasoning } from './router.js';
|
|
17
|
+
// High-level client
|
|
18
|
+
export { DREClient } from './client.js';
|
|
19
|
+
// Integrations
|
|
20
|
+
export { OpenRouterIntegration, MODEL_ID_TO_OPENROUTER } from './integrations/index.js';
|
|
21
|
+
// Configuration
|
|
22
|
+
export { createDefaultConfig, DEFAULT_DATA_DIR, DEFAULT_EMBEDDING_MODEL } from './config.js';
|
|
23
|
+
// Registry
|
|
24
|
+
export { ModelRegistry, ModelInfo, ModelPricing } from './registry/index.js';
|
|
25
|
+
// Scoring
|
|
26
|
+
export { ScoringEngine, SPEED_SCORES } from './scoring/engine.js';
|
|
27
|
+
export { Priorities, DEFAULT_PRIORITIES } from './scoring/priorities.js';
|
|
28
|
+
export { BenchmarkNormalizer, NormalizationRange, NORMALIZATION_RANGES } from './scoring/benchmarks.js';
|
|
29
|
+
// Classifiers
|
|
30
|
+
export { BaseClassifier, emptyClassificationResult, topBenchmarks } from './classifiers/base.js';
|
|
31
|
+
export { EmbeddingClassifier } from './classifiers/embedding.js';
|
|
32
|
+
// Embeddings
|
|
33
|
+
export { BaseEmbeddingProvider } from './embeddings/base.js';
|
|
34
|
+
export { LocalEmbeddingProvider } from './embeddings/local.js';
|
|
35
|
+
// Centroids
|
|
36
|
+
export { CentroidGenerator } from './centroids/generator.js';
|
|
37
|
+
export { CentroidLoader } from './centroids/loader.js';
|
|
38
|
+
// Benchmarks
|
|
39
|
+
export { BenchmarkRegistry } from './benchmarks/registry.js';
|
|
40
|
+
export { STANDARD_BENCHMARKS } from './benchmarks/standard.js';
|
|
41
|
+
// Dashboard (HTML report generator for eval runs)
|
|
42
|
+
export { renderDashboard } from './dashboard/index.js';
|
|
43
|
+
// Budget optimization
|
|
44
|
+
export { costUnitForBudget, estimateGenerationCost, estimateTokens, optimizeBudgetCandidates, paretoPrune, routeDatasetWithBudget, } from './budget.js';
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,cAAc;AACd,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAGtG,oBAAo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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/integrations/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAChF,YAAY,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/integrations/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC"}
|