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
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 TryAII Team
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# tryaii-dre
|
|
2
|
+
|
|
3
|
+
AI model router for Node.js and TypeScript.
|
|
4
|
+
|
|
5
|
+
Ranks models using benchmark performance, pricing, latency, and your quality/cost/speed priorities.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install tryaii-dre
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick Start
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { DREClient, Priorities, Router } from 'tryaii-dre';
|
|
17
|
+
|
|
18
|
+
// Embedding-based classifier using @xenova/transformers.
|
|
19
|
+
const router = new Router();
|
|
20
|
+
|
|
21
|
+
const result = await router.route('Write a Python function to sort an array');
|
|
22
|
+
console.log(result.bestModel); // e.g., "gpt-5.2"
|
|
23
|
+
console.log(result.scores[0]); // Full scoring breakdown
|
|
24
|
+
|
|
25
|
+
// Route with custom priorities
|
|
26
|
+
const budgetResult = await router.route(
|
|
27
|
+
'Explain quantum computing',
|
|
28
|
+
{ priorities: Priorities.budget() } // Favor cheaper models
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
// Route and call the selected model through OpenRouter.
|
|
32
|
+
const client = new DREClient({ apiKey: process.env.OPENROUTER_API_KEY });
|
|
33
|
+
const response = await client.chat('Write a quicksort implementation');
|
|
34
|
+
console.log(response.content);
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## CLI
|
|
38
|
+
|
|
39
|
+
Installing the package adds a `tryaii-dre` command (same surface as the Python SDK). It
|
|
40
|
+
opens with an animated blue→red banner, then runs your command. The banner prints to
|
|
41
|
+
stderr and auto-suppresses when output is piped, so `--json` stays clean.
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
tryaii-dre route "Write a Python function to merge sorted arrays" --quality=5 --cost=1
|
|
45
|
+
tryaii-dre eval prompts.json --output results/run --quality=5 --cost=1 --speed=1
|
|
46
|
+
tryaii-dre eval prompts.json --max-price=0.10 --output-tokens=2000 --budget-mode=fit-output
|
|
47
|
+
tryaii-dre models --provider anthropic # add --json for machine-readable output
|
|
48
|
+
tryaii-dre benchmarks --json
|
|
49
|
+
tryaii-dre setup # download the embedding model + warm centroids
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
| Command | Key options |
|
|
53
|
+
|---------|-------------|
|
|
54
|
+
| `route "<prompt>"` | `--quality/--cost/--speed <1-5>` (default 3), `--top-k <n>` |
|
|
55
|
+
| `eval <input.json>` | `-o/--output <dir>`, `--max-price <usd>`, `--output-tokens <n>`, `--budget-mode strict\|fit-output` |
|
|
56
|
+
| `models` | `--provider <name>`, `--json` |
|
|
57
|
+
| `benchmarks` | `--json` |
|
|
58
|
+
| `setup` / `regenerate` | `--model <name>` |
|
|
59
|
+
|
|
60
|
+
Global flags: `--no-banner` (or `TRYAII_NO_BANNER=1`), `NO_COLOR=1`, `--version`. See the
|
|
61
|
+
[repo README](../../README.md#command-line-interface) for the full reference.
|
|
62
|
+
|
|
63
|
+
## Embedding Provider
|
|
64
|
+
|
|
65
|
+
`Router` uses semantic embeddings to classify prompts against benchmark centroids. The default provider is `LocalEmbeddingProvider` (backed by `@xenova/transformers`), which runs an ONNX MiniLM model locally with no API keys. You can supply a custom provider via the `embeddingProvider` option.
|
|
66
|
+
|
|
67
|
+
### Sync vs. async
|
|
68
|
+
|
|
69
|
+
`router.route()` is **async** -- it works with any embedding provider, including the default `LocalEmbeddingProvider` (which is async-only because the underlying ONNX runtime is async).
|
|
70
|
+
|
|
71
|
+
For the niche case where you have a sync embedding provider (e.g. a custom in-process provider that doesn't do I/O), `router.routeSync()` gives you a blocking call. Calling `routeSync()` with an async-only provider throws a clear error pointing you back to `route()`.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
// Default async path -- works with any provider
|
|
75
|
+
const result = await router.route('Write a sorting algorithm');
|
|
76
|
+
|
|
77
|
+
// Sync path -- requires a sync provider (e.g. injected via the constructor)
|
|
78
|
+
const sync = router.routeSync('Write a sorting algorithm');
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Priorities
|
|
82
|
+
|
|
83
|
+
Control what matters most in model selection:
|
|
84
|
+
|
|
85
|
+
```typescript
|
|
86
|
+
// Presets
|
|
87
|
+
Priorities.balanced() // quality=3, cost=3, speed=3
|
|
88
|
+
Priorities.performance() // quality=5, cost=1, speed=1
|
|
89
|
+
Priorities.budget() // quality=2, cost=5, speed=3
|
|
90
|
+
Priorities.fast() // quality=2, cost=3, speed=5
|
|
91
|
+
|
|
92
|
+
// Custom
|
|
93
|
+
new Priorities(4, 2, 3) // quality=4, cost=2, speed=3
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## Adding Custom Models
|
|
97
|
+
|
|
98
|
+
```typescript
|
|
99
|
+
router.addModel({
|
|
100
|
+
modelId: 'my-custom-model',
|
|
101
|
+
provider: 'custom',
|
|
102
|
+
benchmarks: { 'HumanEval': 85, 'MMLU': 80 },
|
|
103
|
+
pricing: [0.001, 0.002], // [input, output] per 1k tokens
|
|
104
|
+
latency: 'fast',
|
|
105
|
+
});
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Adding Custom Benchmarks
|
|
109
|
+
|
|
110
|
+
`addBenchmark()` is async -- it generates a centroid for the new benchmark using the configured embedding provider, which means it works with the default async `LocalEmbeddingProvider`. Subsequent `route()` calls immediately see the new benchmark.
|
|
111
|
+
|
|
112
|
+
```typescript
|
|
113
|
+
await router.addBenchmark(
|
|
114
|
+
'CustomerSupportQA',
|
|
115
|
+
[
|
|
116
|
+
'How do I reset my password?',
|
|
117
|
+
'I want to cancel my subscription',
|
|
118
|
+
'Where is my order?',
|
|
119
|
+
],
|
|
120
|
+
'Customer support query handling',
|
|
121
|
+
0, // min score
|
|
122
|
+
100, // max score
|
|
123
|
+
);
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
For sync-provider setups there's a `router.addBenchmarkSync(...)` sibling that blocks on centroid generation.
|
|
127
|
+
|
|
128
|
+
## Filtering
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
// Only Anthropic models
|
|
132
|
+
await router.route('prompt', { filterProvider: 'anthropic' });
|
|
133
|
+
|
|
134
|
+
// Only models under $0.01/1k input tokens
|
|
135
|
+
await router.route('prompt', { filterMaxCost: 0.01 });
|
|
136
|
+
|
|
137
|
+
// Only models with specific capabilities
|
|
138
|
+
await router.route('prompt', { filterCapability: 'vision' });
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## High-Level Client
|
|
142
|
+
|
|
143
|
+
Use `DREClient` when you want routing plus chat/streaming in one object:
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { DREClient } from 'tryaii-dre';
|
|
147
|
+
|
|
148
|
+
const client = new DREClient({ apiKey: process.env.OPENROUTER_API_KEY });
|
|
149
|
+
|
|
150
|
+
const route = await client.route('Explain quantum computing');
|
|
151
|
+
console.log(route.bestModel);
|
|
152
|
+
|
|
153
|
+
for await (const chunk of client.stream('Explain machine learning')) {
|
|
154
|
+
process.stdout.write(chunk);
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## OpenRouter Integration
|
|
159
|
+
|
|
160
|
+
Route prompts and call the selected model through OpenRouter:
|
|
161
|
+
|
|
162
|
+
```typescript
|
|
163
|
+
import { OpenRouterIntegration, Router } from 'tryaii-dre';
|
|
164
|
+
|
|
165
|
+
const router = new Router();
|
|
166
|
+
const openrouter = new OpenRouterIntegration(router, {
|
|
167
|
+
apiKey: process.env.OPENROUTER_API_KEY,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const response = await openrouter.chat('Write a quicksort in Python');
|
|
171
|
+
console.log(response.modelUsed); // Which model was selected
|
|
172
|
+
console.log(response.content); // The actual response
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Architecture
|
|
176
|
+
|
|
177
|
+
```
|
|
178
|
+
User Prompt
|
|
179
|
+
|
|
|
180
|
+
v
|
|
181
|
+
[Classifier] --> benchmark similarity scores
|
|
182
|
+
| (HumanEval: 0.8, MMLU: 0.3, ...)
|
|
183
|
+
v
|
|
184
|
+
[ScoringEngine] --> weighted scores per model
|
|
185
|
+
| (quality * qW + cost * cW + speed * sW)
|
|
186
|
+
v
|
|
187
|
+
[RouteResult] --> best model + reasoning
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Eval Dashboard
|
|
191
|
+
|
|
192
|
+
The `tryaii-dre eval` command (above) supports a shared generation budget:
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
tryaii-dre eval prompts.json --output results/node-budget --max-price=0.10 --output-tokens=2000
|
|
196
|
+
tryaii-dre eval prompts.json --output results/node-budget-fit --max-price=0.10 --output-tokens=2000 --budget-mode=fit-output
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
This treats `--max-price` as the total budget for the whole dataset and
|
|
200
|
+
`--output-tokens` as the fixed expected response length per prompt. In budgeted
|
|
201
|
+
eval, quality/cost/speed priority flags are ignored: price is the hard
|
|
202
|
+
constraint, and the optimizer maximizes model quality within that price.
|
|
203
|
+
`--budget-mode=fit-output` lowers that fixed output length when the requested
|
|
204
|
+
length cannot fit the total budget. Each run writes `results.jsonl`,
|
|
205
|
+
`summary.json`, and an `index.html` dashboard.
|
|
206
|
+
|
|
207
|
+
You can also render that dashboard programmatically from any eval run's `summary.json`
|
|
208
|
+
(the same shape the CLI writes). The output is a zero-dependency string you can write next
|
|
209
|
+
to `summary.json` / `results.jsonl` to make the run dir an openable artifact.
|
|
210
|
+
|
|
211
|
+
```ts
|
|
212
|
+
import { readFile, writeFile } from 'node:fs/promises';
|
|
213
|
+
import { join } from 'node:path';
|
|
214
|
+
import { renderDashboard, type DashboardSummary } from 'tryaii-dre';
|
|
215
|
+
|
|
216
|
+
const runDir = './runs/quality';
|
|
217
|
+
const summary: DashboardSummary = JSON.parse(
|
|
218
|
+
await readFile(join(runDir, 'summary.json'), 'utf8'),
|
|
219
|
+
);
|
|
220
|
+
|
|
221
|
+
const html = renderDashboard(summary, runDir);
|
|
222
|
+
await writeFile(join(runDir, 'index.html'), html, 'utf8');
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Pass `{ summaryHref, resultsHref }` as the third argument to override the footer artifact links (useful when rendering to a directory that doesn't sit next to the JSON).
|
|
226
|
+
|
|
227
|
+
## Requirements
|
|
228
|
+
|
|
229
|
+
- Node.js >= 18.0.0
|
|
230
|
+
- TypeScript >= 5.3 (for development)
|
|
231
|
+
|
|
232
|
+
## License
|
|
233
|
+
|
|
234
|
+
Apache 2.0
|
package/dist/banner.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Animated startup banner for the TryAii-DRE CLI.
|
|
3
|
+
*
|
|
4
|
+
* Renders a blue -> red `TRYAII` wordmark to stderr so stdout stays clean for
|
|
5
|
+
* piped / JSON output. Color and animation are suppressed automatically when:
|
|
6
|
+
*
|
|
7
|
+
* - stderr is not a TTY (piped, redirected, or CI) -- nothing is printed
|
|
8
|
+
* - NO_COLOR is set, or TERM=dumb -- printed once, monochrome, no animation
|
|
9
|
+
* - TRYAII_NO_BANNER is set, or --no-banner is passed -- nothing is printed
|
|
10
|
+
*
|
|
11
|
+
* A 24-bit gradient is used when the terminal advertises truecolor
|
|
12
|
+
* (COLORTERM=truecolor/24bit); otherwise a 256-color two-tone fallback is used.
|
|
13
|
+
*
|
|
14
|
+
* Kept intentionally in sync with the Python SDK banner (tryaii_dre/cli/banner.py)
|
|
15
|
+
* so both CLIs greet users identically.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Print the banner to stderr.
|
|
19
|
+
*
|
|
20
|
+
* Safe to call unconditionally: it self-suppresses for non-interactive streams
|
|
21
|
+
* and honors NO_COLOR / TRYAII_NO_BANNER. `animate` can be forced off for tests.
|
|
22
|
+
*/
|
|
23
|
+
export declare function showBanner(animate?: boolean): Promise<void>;
|
|
24
|
+
//# sourceMappingURL=banner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"banner.d.ts","sourceRoot":"","sources":["../src/banner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA0EH;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,OAAO,UAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAuC9D"}
|
package/dist/banner.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Animated startup banner for the TryAii-DRE CLI.
|
|
3
|
+
*
|
|
4
|
+
* Renders a blue -> red `TRYAII` wordmark to stderr so stdout stays clean for
|
|
5
|
+
* piped / JSON output. Color and animation are suppressed automatically when:
|
|
6
|
+
*
|
|
7
|
+
* - stderr is not a TTY (piped, redirected, or CI) -- nothing is printed
|
|
8
|
+
* - NO_COLOR is set, or TERM=dumb -- printed once, monochrome, no animation
|
|
9
|
+
* - TRYAII_NO_BANNER is set, or --no-banner is passed -- nothing is printed
|
|
10
|
+
*
|
|
11
|
+
* A 24-bit gradient is used when the terminal advertises truecolor
|
|
12
|
+
* (COLORTERM=truecolor/24bit); otherwise a 256-color two-tone fallback is used.
|
|
13
|
+
*
|
|
14
|
+
* Kept intentionally in sync with the Python SDK banner (tryaii_dre/cli/banner.py)
|
|
15
|
+
* so both CLIs greet users identically.
|
|
16
|
+
*/
|
|
17
|
+
import { createRequire } from 'node:module';
|
|
18
|
+
/** Big "TRYAII" wordmark (ANSI Shadow style). All rows are the same width. */
|
|
19
|
+
const ART = [
|
|
20
|
+
'████████╗██████╗ ██╗ ██╗ █████╗ ██╗██╗',
|
|
21
|
+
'╚══██╔══╝██╔══██╗╚██╗ ██╔╝██╔══██╗██║██║',
|
|
22
|
+
' ██║ ██████╔╝ ╚████╔╝ ███████║██║██║',
|
|
23
|
+
' ██║ ██╔══██╗ ╚██╔╝ ██╔══██║██║██║',
|
|
24
|
+
' ██║ ██║ ██║ ██║ ██║ ██║██║██║',
|
|
25
|
+
' ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚═╝',
|
|
26
|
+
];
|
|
27
|
+
// Gradient endpoints: vivid blue -> vivid red.
|
|
28
|
+
const BLUE = [56, 132, 255];
|
|
29
|
+
const RED = [244, 63, 94];
|
|
30
|
+
// 256-color fallback endpoints (DeepSkyBlue / IndianRed).
|
|
31
|
+
const BLUE_256 = '\x1b[38;5;39m';
|
|
32
|
+
const RED_256 = '\x1b[38;5;203m';
|
|
33
|
+
const RESET = '\x1b[0m';
|
|
34
|
+
const DIM = '\x1b[2m';
|
|
35
|
+
const FRAME_DELAY_MS = 22;
|
|
36
|
+
function supportsColor(stream) {
|
|
37
|
+
if (process.env.NO_COLOR)
|
|
38
|
+
return false;
|
|
39
|
+
if (process.env.TERM === 'dumb')
|
|
40
|
+
return false;
|
|
41
|
+
return Boolean(stream.isTTY);
|
|
42
|
+
}
|
|
43
|
+
function truecolor() {
|
|
44
|
+
const value = (process.env.COLORTERM ?? '').toLowerCase();
|
|
45
|
+
return value === 'truecolor' || value === '24bit';
|
|
46
|
+
}
|
|
47
|
+
function lerp(start, end, t) {
|
|
48
|
+
return Math.round(start + (end - start) * t);
|
|
49
|
+
}
|
|
50
|
+
/** Color each character by its column position across the wordmark. */
|
|
51
|
+
function gradient(text, width) {
|
|
52
|
+
const span = Math.max(width - 1, 1);
|
|
53
|
+
let out = '';
|
|
54
|
+
for (let i = 0; i < text.length; i++) {
|
|
55
|
+
const t = i / span;
|
|
56
|
+
const r = lerp(BLUE[0], RED[0], t);
|
|
57
|
+
const g = lerp(BLUE[1], RED[1], t);
|
|
58
|
+
const b = lerp(BLUE[2], RED[2], t);
|
|
59
|
+
out += `\x1b[38;2;${r};${g};${b}m${text[i]}`;
|
|
60
|
+
}
|
|
61
|
+
return out + RESET;
|
|
62
|
+
}
|
|
63
|
+
/** Fallback: blue first ~62%, red remainder (256-color). */
|
|
64
|
+
function twoTone(text) {
|
|
65
|
+
const split = Math.floor(text.length * 0.62);
|
|
66
|
+
return `${BLUE_256}${text.slice(0, split)}${RED_256}${text.slice(split)}${RESET}`;
|
|
67
|
+
}
|
|
68
|
+
function packageVersion() {
|
|
69
|
+
try {
|
|
70
|
+
const require = createRequire(import.meta.url);
|
|
71
|
+
const pkg = require('../package.json');
|
|
72
|
+
return pkg.version ?? '';
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return '';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
79
|
+
/**
|
|
80
|
+
* Print the banner to stderr.
|
|
81
|
+
*
|
|
82
|
+
* Safe to call unconditionally: it self-suppresses for non-interactive streams
|
|
83
|
+
* and honors NO_COLOR / TRYAII_NO_BANNER. `animate` can be forced off for tests.
|
|
84
|
+
*/
|
|
85
|
+
export async function showBanner(animate = true) {
|
|
86
|
+
const stream = process.stderr;
|
|
87
|
+
if (process.env.TRYAII_NO_BANNER)
|
|
88
|
+
return;
|
|
89
|
+
if (!stream.isTTY)
|
|
90
|
+
return; // keep redirected / piped / CI output clean
|
|
91
|
+
const color = supportsColor(stream);
|
|
92
|
+
const width = Math.max(...ART.map((line) => line.length));
|
|
93
|
+
const colorize = color
|
|
94
|
+
? truecolor()
|
|
95
|
+
? gradient
|
|
96
|
+
: (line) => twoTone(line)
|
|
97
|
+
: null;
|
|
98
|
+
const doAnimate = animate && color;
|
|
99
|
+
try {
|
|
100
|
+
for (const line of ART) {
|
|
101
|
+
stream.write((colorize ? colorize(line, width) : line) + '\n');
|
|
102
|
+
if (doAnimate)
|
|
103
|
+
await sleep(FRAME_DELAY_MS);
|
|
104
|
+
}
|
|
105
|
+
const rule = '─'.repeat(width);
|
|
106
|
+
const version = packageVersion();
|
|
107
|
+
const ver = version ? ` · v${version}` : '';
|
|
108
|
+
const ruleLine = colorize ? colorize(rule, width) : rule;
|
|
109
|
+
const tagline = 'semantic, prompt-aware LLM routing · benchmarks × cost × speed';
|
|
110
|
+
if (color) {
|
|
111
|
+
stream.write(ruleLine + '\n');
|
|
112
|
+
stream.write(` Diff Routing Engine${DIM}${ver}${RESET}\n`);
|
|
113
|
+
stream.write(`${DIM} ${tagline}${RESET}\n\n`);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
stream.write(ruleLine + '\n');
|
|
117
|
+
stream.write(` Diff Routing Engine${ver}\n`);
|
|
118
|
+
stream.write(` ${tagline}\n\n`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
// Never let a cosmetic banner break the actual command.
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=banner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"banner.js","sourceRoot":"","sources":["../src/banner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,8EAA8E;AAC9E,MAAM,GAAG,GAAG;IACV,0CAA0C;IAC1C,0CAA0C;IAC1C,0CAA0C;IAC1C,0CAA0C;IAC1C,0CAA0C;IAC1C,0CAA0C;CAC3C,CAAC;AAEF,+CAA+C;AAC/C,MAAM,IAAI,GAA6B,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AACtD,MAAM,GAAG,GAA6B,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC;AAEpD,0DAA0D;AAC1D,MAAM,QAAQ,GAAG,eAAe,CAAC;AACjC,MAAM,OAAO,GAAG,gBAAgB,CAAC;AAEjC,MAAM,KAAK,GAAG,SAAS,CAAC;AACxB,M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C9B,MAAM,CAAC,KAAK,CAAC,wBAAwB,GAAG,GAAG,GAAG,GAAG,KAAK,IAAI,CAAC,CAAC;YAC5D,MAAM,CAAC,KAAK,CAAC,GAAG,GAAG,KAAK,OAAO,GAAG,KAAK,MAAM,CAAC,CAAC;QACjD,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC;YAC9B,MAAM,CAAC,KAAK,CAAC,wBAAwB,GAAG,IAAI,CAAC,CAAC;YAC9C,MAAM,CAAC,KAAK,CAAC,KAAK,OAAO,MAAM,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,wDAAwD;IAC1D,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/benchmarks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACtF,YAAY,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/benchmarks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEtF,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extensible benchmark registry.
|
|
3
|
+
*
|
|
4
|
+
* Allows users to register custom benchmarks with their own training queries
|
|
5
|
+
* and normalization ranges. Designed for high connectivity with external
|
|
6
|
+
* benchmark-creation tools.
|
|
7
|
+
*/
|
|
8
|
+
import { BenchmarkNormalizer, NormalizationRange } from '../scoring/benchmarks.js';
|
|
9
|
+
/** Complete definition of a benchmark. */
|
|
10
|
+
export interface BenchmarkDefinition {
|
|
11
|
+
/** Benchmark name (e.g., "MMLU"). */
|
|
12
|
+
name: string;
|
|
13
|
+
/** Human-readable description. */
|
|
14
|
+
description: string;
|
|
15
|
+
/** Representative prompts for centroid generation. */
|
|
16
|
+
trainingQueries: string[];
|
|
17
|
+
/** Normalization range for raw scores. */
|
|
18
|
+
normalization: NormalizationRange;
|
|
19
|
+
/** Broad category (TECHNICAL, CREATIVE, etc.). */
|
|
20
|
+
broadCategory: string;
|
|
21
|
+
/** Subcategories this benchmark covers. */
|
|
22
|
+
subcategories: string[];
|
|
23
|
+
/** Optional metadata. */
|
|
24
|
+
metadata: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
/** Create a BenchmarkDefinition from a plain object (e.g. loaded from JSON). */
|
|
27
|
+
export declare function benchmarkFromDict(d: Record<string, unknown>): BenchmarkDefinition;
|
|
28
|
+
/** Serialize a BenchmarkDefinition to a plain object. */
|
|
29
|
+
export declare function benchmarkToDict(b: BenchmarkDefinition): Record<string, unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* Registry for benchmark definitions.
|
|
32
|
+
*
|
|
33
|
+
* Provides a clean interface for:
|
|
34
|
+
* - Registering custom benchmarks
|
|
35
|
+
* - Loading benchmarks from JSON files (for tool connectivity)
|
|
36
|
+
* - Exporting benchmark definitions
|
|
37
|
+
* - Integrating with the centroid generator and scoring engine
|
|
38
|
+
*/
|
|
39
|
+
export declare class BenchmarkRegistry {
|
|
40
|
+
private _benchmarks;
|
|
41
|
+
constructor();
|
|
42
|
+
/** Create registry with the standard 12 benchmarks. */
|
|
43
|
+
static default(): BenchmarkRegistry;
|
|
44
|
+
/** Register a new benchmark or update an existing one. */
|
|
45
|
+
register(benchmark: BenchmarkDefinition): void;
|
|
46
|
+
/** Remove a benchmark. Returns true if it existed. */
|
|
47
|
+
unregister(name: string): boolean;
|
|
48
|
+
/** Get a benchmark by name. */
|
|
49
|
+
get(name: string): BenchmarkDefinition | undefined;
|
|
50
|
+
/** All registered benchmark names. */
|
|
51
|
+
get names(): string[];
|
|
52
|
+
/** All registered benchmarks. */
|
|
53
|
+
get allBenchmarks(): BenchmarkDefinition[];
|
|
54
|
+
/** Get all training queries grouped by benchmark name. */
|
|
55
|
+
getTrainingQueries(): Record<string, string[]>;
|
|
56
|
+
/** Create a BenchmarkNormalizer from all registered benchmarks. */
|
|
57
|
+
getNormalizer(): BenchmarkNormalizer;
|
|
58
|
+
/**
|
|
59
|
+
* Load benchmarks from a JSON file.
|
|
60
|
+
*
|
|
61
|
+
* @returns Number of benchmarks loaded.
|
|
62
|
+
*/
|
|
63
|
+
loadFromFile(path: string): number;
|
|
64
|
+
/** Export all benchmarks to a JSON file. */
|
|
65
|
+
exportToFile(path: string): void;
|
|
66
|
+
get length(): number;
|
|
67
|
+
has(name: string): boolean;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=registry.d.ts.map
|