adaptive-memory-multi-model-router 2.2.5 → 2.2.7
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/README.md +149 -116
- package/README.md.bak +836 -0
- package/assets/benchmark-results.png +0 -0
- package/assets/complexity-scoring-v2.png +0 -0
- package/assets/complexity-scoring.png +0 -0
- package/assets/cost-comparison-chart.png +0 -0
- package/assets/cost-comparison-v2.png +0 -0
- package/assets/feature-comparison-v2.png +0 -0
- package/assets/feature-comparison-v3.png +0 -0
- package/assets/provider-health-chart.png +0 -0
- package/assets/provider-health-v2.png +0 -0
- package/assets/routing-flow-v2.png +0 -0
- package/assets/routing-flow-v3.png +0 -0
- package/assets/routing-flow.png +0 -0
- package/assets/tier-distribution.png +0 -0
- package/benchmark-results.json +620 -46
- package/dist/cache/cacheKeyGenerator.d.ts +67 -0
- package/dist/cache/cacheKeyGenerator.d.ts.map +1 -0
- package/dist/cache/cacheKeyGenerator.js +211 -0
- package/dist/cache/cacheKeyGenerator.js.map +1 -0
- package/dist/cli.js +0 -0
- package/dist/cost/preCallCostEstimator.d.ts +114 -0
- package/dist/cost/preCallCostEstimator.d.ts.map +1 -0
- package/dist/cost/preCallCostEstimator.js +256 -0
- package/dist/cost/preCallCostEstimator.js.map +1 -0
- package/dist/inference/speculativeDecoding.d.ts +133 -0
- package/dist/inference/speculativeDecoding.d.ts.map +1 -0
- package/dist/inference/speculativeDecoding.js +276 -0
- package/dist/inference/speculativeDecoding.js.map +1 -0
- package/dist/providers/providerHealth.d.ts +117 -0
- package/dist/providers/providerHealth.d.ts.map +1 -0
- package/dist/providers/providerHealth.js +309 -0
- package/dist/providers/providerHealth.js.map +1 -0
- package/dist/routing/difficultyClassifier.d.ts +79 -0
- package/dist/routing/difficultyClassifier.d.ts.map +1 -0
- package/dist/routing/difficultyClassifier.js +329 -0
- package/dist/routing/difficultyClassifier.js.map +1 -0
- package/dist/sdk.d.ts +125 -0
- package/dist/sdk.d.ts.map +1 -0
- package/dist/sdk.js.map +1 -0
- package/package.json +2 -322
- package/scripts/run-mmlu-benchmark.js +176 -0
- package/scripts/run-provider-benchmark.js +244 -0
- package/src/cache/cacheKeyGenerator.ts +242 -0
- package/src/cost/preCallCostEstimator.ts +345 -0
- package/src/inference/speculativeDecoding.ts +373 -0
- package/src/providers/providerHealth.ts +397 -0
- package/src/routing/difficultyClassifier.ts +420 -0
- package/test/provider-test.js +69 -90
- package/test.js +43 -69
- package/test.js.bak +376 -0
- package/src/skills/__tests__/skill_manager.test.ts +0 -328
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* A3M Router - Difficulty Classifier
|
|
4
|
+
*
|
|
5
|
+
* Classifies queries as simple/medium/complex based on features.
|
|
6
|
+
* Used to route queries to appropriate model tiers.
|
|
7
|
+
*
|
|
8
|
+
* Usage:
|
|
9
|
+
* const classifier = new DifficultyClassifier();
|
|
10
|
+
* const result = classifier.classify("What is Python?");
|
|
11
|
+
* console.log(result); // { level: 'simple', confidence: 0.85, signals: [...] }
|
|
12
|
+
*
|
|
13
|
+
* const complex = classifier.classify("Implement a red-black tree in Rust with full tests");
|
|
14
|
+
* console.log(complex); // { level: 'complex', confidence: 0.92, signals: [...] }
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.DifficultyClassifier = void 0;
|
|
18
|
+
exports.createDifficultyClassifier = createDifficultyClassifier;
|
|
19
|
+
const DEFAULT_CONFIG = {
|
|
20
|
+
thresholds: {
|
|
21
|
+
simpleMax: 0.35,
|
|
22
|
+
mediumMax: 0.65,
|
|
23
|
+
},
|
|
24
|
+
useKeywords: true,
|
|
25
|
+
useLinguistic: true,
|
|
26
|
+
};
|
|
27
|
+
// ============================================================
|
|
28
|
+
// Signal patterns
|
|
29
|
+
// ============================================================
|
|
30
|
+
const COMPLEX_KEYWORDS = [
|
|
31
|
+
// Math/Science
|
|
32
|
+
'calculate', 'compute', 'algorithm', 'mathematical', 'equation',
|
|
33
|
+
'statistical', 'probability', 'derivative', 'integral', 'matrix',
|
|
34
|
+
'vector', 'optimize', 'optimization', 'minimize', 'maximize',
|
|
35
|
+
// Code
|
|
36
|
+
'implement', 'refactor', 'architect', 'design pattern', 'factory',
|
|
37
|
+
'singleton', 'decorator', 'middleware', 'pipeline', 'async',
|
|
38
|
+
'concurrency', 'parallel', 'thread', 'process', 'memory leak',
|
|
39
|
+
'database', 'sql', 'nosql', 'index', 'shard', 'replica',
|
|
40
|
+
'api', 'rest', 'graphql', 'microservice', 'container', 'kubernetes',
|
|
41
|
+
'deploy', 'ci/cd', 'pipeline', 'test', 'mock', 'stub',
|
|
42
|
+
// Reasoning
|
|
43
|
+
'analyze', 'compare', 'contrast', 'evaluate', 'synthesis',
|
|
44
|
+
'implications', 'hypothesis', 'theory', 'principle', 'why does',
|
|
45
|
+
'explain why', 'reasoning', 'logical', 'deduce', 'infer',
|
|
46
|
+
// Academic/Complex
|
|
47
|
+
'research', 'comprehensive', 'detailed', 'thorough', 'extensive',
|
|
48
|
+
'in-depth', 'multi-step', 'hierarchical', 'nested', 'recursive',
|
|
49
|
+
];
|
|
50
|
+
const SIMPLE_KEYWORDS = [
|
|
51
|
+
'what is', 'who is', 'when did', 'where is', 'simple',
|
|
52
|
+
'basic', 'intro', 'tutorial', 'hello', 'hi ',
|
|
53
|
+
'thanks', 'please', 'help me', 'quick', 'brief',
|
|
54
|
+
'yes', 'no', 'maybe', 'ok', 'sure', 'okay',
|
|
55
|
+
'list of', 'names of', 'definition', 'meaning of',
|
|
56
|
+
];
|
|
57
|
+
const CODE_INDICATORS = [
|
|
58
|
+
'code', 'function', 'class', 'method', 'variable',
|
|
59
|
+
'const', 'let', 'var', 'return', 'import', 'export',
|
|
60
|
+
'def ', 'fn ', 'pub ', 'struct', 'enum', 'trait',
|
|
61
|
+
'python', 'javascript', 'typescript', 'java', 'rust', 'go',
|
|
62
|
+
'html', 'css', 'sql', 'bash', 'shell', 'script',
|
|
63
|
+
'bug', 'error', 'exception', 'debug', 'stack trace',
|
|
64
|
+
'api', 'endpoint', 'route', 'handler', 'controller',
|
|
65
|
+
];
|
|
66
|
+
const REASONING_INDICATORS = [
|
|
67
|
+
'why', 'how', 'because', 'therefore', 'thus',
|
|
68
|
+
'reasoning', 'logic', 'deduce', 'infer', 'conclude',
|
|
69
|
+
'implies', 'suggest', 'indicate', 'evidence',
|
|
70
|
+
'analyze', 'investigate', 'examine', 'evaluate',
|
|
71
|
+
'compare', 'differences', 'similar', 'versus',
|
|
72
|
+
'if then', 'hypothesis', 'assumption', 'premise',
|
|
73
|
+
];
|
|
74
|
+
// ============================================================
|
|
75
|
+
// DifficultyClassifier
|
|
76
|
+
// ============================================================
|
|
77
|
+
class DifficultyClassifier {
|
|
78
|
+
config;
|
|
79
|
+
trainingData = [];
|
|
80
|
+
constructor(config = {}) {
|
|
81
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Classify a query's difficulty.
|
|
85
|
+
*/
|
|
86
|
+
classify(query) {
|
|
87
|
+
const query_lower = query.toLowerCase();
|
|
88
|
+
const words = query.split(/\s+/);
|
|
89
|
+
// Calculate feature scores
|
|
90
|
+
const features = {
|
|
91
|
+
length: this.calculateLengthScore(query),
|
|
92
|
+
keywords: this.calculateKeywordScore(query_lower),
|
|
93
|
+
reasoning: this.calculateReasoningScore(query_lower, words),
|
|
94
|
+
language: this.calculateLanguageScore(query_lower, words),
|
|
95
|
+
code: this.calculateCodeScore(query_lower),
|
|
96
|
+
};
|
|
97
|
+
// Weighted combination
|
|
98
|
+
const rawScore = features.length * 0.15 +
|
|
99
|
+
features.keywords * 0.30 +
|
|
100
|
+
features.reasoning * 0.20 +
|
|
101
|
+
features.language * 0.15 +
|
|
102
|
+
features.code * 0.20;
|
|
103
|
+
// Clamp and determine level
|
|
104
|
+
const score = Math.max(0, Math.min(1, rawScore));
|
|
105
|
+
const level = this.determineLevel(score);
|
|
106
|
+
const confidence = this.calculateConfidence(features, score);
|
|
107
|
+
// Generate signals list
|
|
108
|
+
const signals = this.generateSignals(query_lower, features);
|
|
109
|
+
// Determine recommended tier
|
|
110
|
+
const { recommendedTier, alternativeTiers } = this.determineTier(level, features);
|
|
111
|
+
return {
|
|
112
|
+
level,
|
|
113
|
+
confidence: Math.round(confidence * 1000) / 1000,
|
|
114
|
+
signals,
|
|
115
|
+
features: {
|
|
116
|
+
length: Math.round(features.length * 1000) / 1000,
|
|
117
|
+
keywords: Math.round(features.keywords * 1000) / 1000,
|
|
118
|
+
reasoning: Math.round(features.reasoning * 1000) / 1000,
|
|
119
|
+
language: Math.round(features.language * 1000) / 1000,
|
|
120
|
+
code: Math.round(features.code * 1000) / 1000,
|
|
121
|
+
},
|
|
122
|
+
recommendedTier,
|
|
123
|
+
alternativeTiers,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Classify multiple queries.
|
|
128
|
+
*/
|
|
129
|
+
classifyBatch(queries) {
|
|
130
|
+
return queries.map(q => this.classify(q));
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Add training example for future improvements.
|
|
134
|
+
*/
|
|
135
|
+
addTrainingExample(query, level) {
|
|
136
|
+
this.trainingData.push({ text: query, level });
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get distribution of difficulties in a batch.
|
|
140
|
+
*/
|
|
141
|
+
getDistribution(queries) {
|
|
142
|
+
const results = this.classifyBatch(queries);
|
|
143
|
+
const total = results.length;
|
|
144
|
+
const distribution = { simple: 0, medium: 0, complex: 0 };
|
|
145
|
+
for (const r of results) {
|
|
146
|
+
distribution[r.level]++;
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
simple: Math.round((distribution.simple / total) * 1000) / 1000,
|
|
150
|
+
medium: Math.round((distribution.medium / total) * 1000) / 1000,
|
|
151
|
+
complex: Math.round((distribution.complex / total) * 1000) / 1000,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
// ---- Feature calculations ----
|
|
155
|
+
calculateLengthScore(query) {
|
|
156
|
+
const words = query.split(/\s+/).length;
|
|
157
|
+
const chars = query.length;
|
|
158
|
+
// Normalize: 1-10 words = simple, 10-50 = medium, 50+ = complex
|
|
159
|
+
const wordScore = Math.min(words / 50, 1.0);
|
|
160
|
+
const charScore = Math.min(chars / 500, 1.0);
|
|
161
|
+
return (wordScore * 0.6 + charScore * 0.4);
|
|
162
|
+
}
|
|
163
|
+
calculateKeywordScore(query) {
|
|
164
|
+
if (!this.config.useKeywords)
|
|
165
|
+
return 0.5;
|
|
166
|
+
let score = 0.5; // Base score
|
|
167
|
+
// Check for complex keywords
|
|
168
|
+
for (const kw of COMPLEX_KEYWORDS) {
|
|
169
|
+
if (query.includes(kw))
|
|
170
|
+
score += 0.1;
|
|
171
|
+
}
|
|
172
|
+
// Check for simple keywords
|
|
173
|
+
for (const kw of SIMPLE_KEYWORDS) {
|
|
174
|
+
if (query.includes(kw))
|
|
175
|
+
score -= 0.15;
|
|
176
|
+
}
|
|
177
|
+
return Math.max(0, Math.min(1, score));
|
|
178
|
+
}
|
|
179
|
+
calculateReasoningScore(query, words) {
|
|
180
|
+
let score = 0.2; // Base score
|
|
181
|
+
// Check reasoning indicators
|
|
182
|
+
for (const indicator of REASONING_INDICATORS) {
|
|
183
|
+
if (query.includes(indicator))
|
|
184
|
+
score += 0.12;
|
|
185
|
+
}
|
|
186
|
+
// "How" questions often require explanation
|
|
187
|
+
if (query.startsWith('how'))
|
|
188
|
+
score += 0.1;
|
|
189
|
+
// Multi-step indicators (first, then, finally, etc.)
|
|
190
|
+
const multiStep = ['first', 'then', 'next', 'finally', 'after', 'before'];
|
|
191
|
+
const hasMultiStep = multiStep.filter(m => query.includes(m)).length;
|
|
192
|
+
score += hasMultiStep * 0.05;
|
|
193
|
+
// Question length (>3 words after question word = more complex)
|
|
194
|
+
if (words.length > 10)
|
|
195
|
+
score += 0.1;
|
|
196
|
+
return Math.max(0, Math.min(1, score));
|
|
197
|
+
}
|
|
198
|
+
calculateLanguageScore(query, words) {
|
|
199
|
+
if (!this.config.useLinguistic)
|
|
200
|
+
return 0.5;
|
|
201
|
+
// Simple heuristics for language complexity
|
|
202
|
+
// Average word length (longer words = more complex)
|
|
203
|
+
const avgWordLen = words.reduce((sum, w) => sum + w.length, 0) / words.length;
|
|
204
|
+
const lenScore = Math.min((avgWordLen - 3) / 4, 1.0); // 3 chars = simple, 7+ = complex
|
|
205
|
+
// Presence of technical/academic vocabulary
|
|
206
|
+
const technicalWords = [
|
|
207
|
+
'analysis', 'methodology', 'framework', 'paradigm', 'synthesis',
|
|
208
|
+
'theoretical', 'empirical', 'conceptual', 'phenomenon', 'correlation',
|
|
209
|
+
];
|
|
210
|
+
let techCount = 0;
|
|
211
|
+
for (const tw of technicalWords) {
|
|
212
|
+
if (query.includes(tw))
|
|
213
|
+
techCount++;
|
|
214
|
+
}
|
|
215
|
+
const techScore = Math.min(techCount * 0.15, 0.4);
|
|
216
|
+
// Sentence complexity (commas, semicolons)
|
|
217
|
+
const punctCount = (query.match(/[,;:]/g) || []).length;
|
|
218
|
+
const punctScore = Math.min(punctCount * 0.1, 0.3);
|
|
219
|
+
return Math.max(0, Math.min(1, 0.3 + lenScore * 0.3 + techScore + punctScore));
|
|
220
|
+
}
|
|
221
|
+
calculateCodeScore(query) {
|
|
222
|
+
let score = 0.1; // Base score (low probability of code)
|
|
223
|
+
// Check code indicators
|
|
224
|
+
for (const indicator of CODE_INDICATORS) {
|
|
225
|
+
if (query.includes(indicator))
|
|
226
|
+
score += 0.1;
|
|
227
|
+
}
|
|
228
|
+
// Code block indicators
|
|
229
|
+
if (query.includes('```') || query.includes('`'))
|
|
230
|
+
score += 0.15;
|
|
231
|
+
// Programming language mentions
|
|
232
|
+
const langs = ['python', 'javascript', 'java', 'rust', 'go', 'c++', 'typescript', 'ruby'];
|
|
233
|
+
for (const lang of langs) {
|
|
234
|
+
if (query.includes(lang))
|
|
235
|
+
score += 0.1;
|
|
236
|
+
}
|
|
237
|
+
// Code-like patterns (brackets, semicolons in unusual contexts)
|
|
238
|
+
if (/[{}\[\];]/.test(query))
|
|
239
|
+
score += 0.1;
|
|
240
|
+
return Math.max(0, Math.min(1, score));
|
|
241
|
+
}
|
|
242
|
+
// ---- Classification ----
|
|
243
|
+
determineLevel(score) {
|
|
244
|
+
if (score <= this.config.thresholds.simpleMax) {
|
|
245
|
+
return 'simple';
|
|
246
|
+
}
|
|
247
|
+
if (score <= this.config.thresholds.mediumMax) {
|
|
248
|
+
return 'medium';
|
|
249
|
+
}
|
|
250
|
+
return 'complex';
|
|
251
|
+
}
|
|
252
|
+
calculateConfidence(features, score) {
|
|
253
|
+
// Higher agreement between features = higher confidence
|
|
254
|
+
const featureValues = Object.values(features);
|
|
255
|
+
const mean = featureValues.reduce((a, b) => a + b, 0) / featureValues.length;
|
|
256
|
+
const variance = featureValues.reduce((sum, f) => sum + Math.pow(f - mean, 2), 0) / featureValues.length;
|
|
257
|
+
const stdDev = Math.sqrt(variance);
|
|
258
|
+
// Low variance = high confidence
|
|
259
|
+
const agreement = 1 - Math.min(stdDev * 2, 1);
|
|
260
|
+
// Distance from 0.5 also matters (extreme scores = more confident)
|
|
261
|
+
const extremity = Math.abs(score - 0.5) * 2;
|
|
262
|
+
return (agreement * 0.6 + extremity * 0.4);
|
|
263
|
+
}
|
|
264
|
+
// ---- Signal generation ----
|
|
265
|
+
generateSignals(query, features) {
|
|
266
|
+
const signals = [];
|
|
267
|
+
if (features.length > 0.6)
|
|
268
|
+
signals.push('long query');
|
|
269
|
+
if (features.length < 0.2)
|
|
270
|
+
signals.push('short query');
|
|
271
|
+
if (features.keywords > 0.6)
|
|
272
|
+
signals.push('complex vocabulary');
|
|
273
|
+
if (features.keywords < 0.3)
|
|
274
|
+
signals.push('simple vocabulary');
|
|
275
|
+
if (features.code > 0.5)
|
|
276
|
+
signals.push('code-related');
|
|
277
|
+
if (features.reasoning > 0.5)
|
|
278
|
+
signals.push('reasoning required');
|
|
279
|
+
if (features.language > 0.6)
|
|
280
|
+
signals.push('complex language');
|
|
281
|
+
// Specific keyword matches
|
|
282
|
+
for (const kw of COMPLEX_KEYWORDS) {
|
|
283
|
+
if (query.includes(kw))
|
|
284
|
+
signals.push(`keyword: ${kw.slice(0, 10)}`);
|
|
285
|
+
}
|
|
286
|
+
return signals;
|
|
287
|
+
}
|
|
288
|
+
// ---- Tier determination ----
|
|
289
|
+
determineTier(level, features) {
|
|
290
|
+
if (level === 'simple') {
|
|
291
|
+
return {
|
|
292
|
+
recommendedTier: 'cheap',
|
|
293
|
+
alternativeTiers: ['free', 'mid'],
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
if (level === 'medium') {
|
|
297
|
+
// Medium but with high code = needs better model
|
|
298
|
+
if (features.code > 0.5) {
|
|
299
|
+
return {
|
|
300
|
+
recommendedTier: 'mid',
|
|
301
|
+
alternativeTiers: ['premium', 'cheap'],
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
return {
|
|
305
|
+
recommendedTier: 'mid',
|
|
306
|
+
alternativeTiers: ['cheap', 'premium'],
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
// Complex
|
|
310
|
+
if (features.code > 0.6 || features.reasoning > 0.6) {
|
|
311
|
+
return {
|
|
312
|
+
recommendedTier: 'premium',
|
|
313
|
+
alternativeTiers: ['mid', 'enterprise'],
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
recommendedTier: 'premium',
|
|
318
|
+
alternativeTiers: ['mid', 'enterprise'],
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
exports.DifficultyClassifier = DifficultyClassifier;
|
|
323
|
+
// ============================================================
|
|
324
|
+
// Factory
|
|
325
|
+
// ============================================================
|
|
326
|
+
function createDifficultyClassifier(config) {
|
|
327
|
+
return new DifficultyClassifier(config);
|
|
328
|
+
}
|
|
329
|
+
//# sourceMappingURL=difficultyClassifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"difficultyClassifier.js","sourceRoot":"","sources":["../../src/routing/difficultyClassifier.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;AAkZH,gEAIC;AA3WD,MAAM,cAAc,GAA+B;IACjD,UAAU,EAAE;QACV,SAAS,EAAE,IAAI;QACf,SAAS,EAAE,IAAI;KAChB;IACD,WAAW,EAAE,IAAI;IACjB,aAAa,EAAE,IAAI;CACpB,CAAC;AAEF,+DAA+D;AAC/D,kBAAkB;AAClB,+DAA+D;AAE/D,MAAM,gBAAgB,GAAG;IACvB,eAAe;IACf,WAAW,EAAE,SAAS,EAAE,WAAW,EAAE,cAAc,EAAE,UAAU;IAC/D,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ;IAChE,QAAQ,EAAE,UAAU,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU;IAC5D,OAAO;IACP,WAAW,EAAE,UAAU,EAAE,WAAW,EAAE,gBAAgB,EAAE,SAAS;IACjE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,UAAU,EAAE,OAAO;IAC3D,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,aAAa;IAC7D,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS;IACvD,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY;IACnE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IACrD,YAAY;IACZ,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW;IACzD,cAAc,EAAE,YAAY,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU;IAC/D,aAAa,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,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,IAAI,GAAG,GAAG,EAAE,CAAC;gBACxB,OAAO;oBACL,eAAe,EAAE,KAAK;oBACtB,gBAAgB,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC;iBACvC,CAAC;YACJ,CAAC;YACD,OAAO;gBACL,eAAe,EAAE,KAAK;gBACtB,gBAAgB,EAAE,CAAC,OAAO,EAAE,SAAS,CAAC;aACvC,CAAC;QACJ,CAAC;QAED,UAAU;QACV,IAAI,QAAQ,CAAC,IAAI,GAAG,GAAG,IAAI,QAAQ,CAAC,SAAS,GAAG,GAAG,EAAE,CAAC;YACpD,OAAO;gBACL,eAAe,EAAE,SAAS;gBAC1B,gBAAgB,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC;aACxC,CAAC;QACJ,CAAC;QACD,OAAO;YACL,eAAe,EAAE,SAAS;YAC1B,gBAAgB,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC;SACxC,CAAC;IACJ,CAAC;CACF;AAhSD,oDAgSC;AAED,+DAA+D;AAC/D,UAAU;AACV,+DAA+D;AAE/D,SAAgB,0BAA0B,CACxC,MAAyB;IAEzB,OAAO,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC;AAC1C,CAAC"}
|
package/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A3M Router TypeScript SDK
|
|
3
|
+
*
|
|
4
|
+
* Clean wrapper class providing a better DX than raw exports.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* import { A3MRouter } from 'adaptive-memory-multi-model-router/sdk';
|
|
8
|
+
*
|
|
9
|
+
* const router = new A3MRouter();
|
|
10
|
+
*
|
|
11
|
+
* // Route a query (no execution, just model selection)
|
|
12
|
+
* const decision = router.route("What is 2+2?");
|
|
13
|
+
* console.log(decision.model, decision.tier, decision.cost);
|
|
14
|
+
*
|
|
15
|
+
* // Start the OpenAI-compatible proxy server
|
|
16
|
+
* const proxyURL = await router.serve(8787);
|
|
17
|
+
*
|
|
18
|
+
* // Use with any OpenAI SDK
|
|
19
|
+
* import OpenAI from 'openai';
|
|
20
|
+
* const client = new OpenAI({ baseURL: router.proxyURL });
|
|
21
|
+
* const response = await client.chat.completions.create({
|
|
22
|
+
* model: 'auto',
|
|
23
|
+
* messages: [{ role: 'user', content: 'Hello' }]
|
|
24
|
+
* });
|
|
25
|
+
*/
|
|
26
|
+
export interface RoutingResult {
|
|
27
|
+
/** Selected model identifier (e.g. "groq/llama-3.3-70b-versatile") */
|
|
28
|
+
model: string;
|
|
29
|
+
/** Cost tier classification */
|
|
30
|
+
tier: 'free' | 'cheap' | 'mid' | 'premium';
|
|
31
|
+
/** Estimated cost in USD */
|
|
32
|
+
cost: number;
|
|
33
|
+
/** Complexity score 0.0–1.0 */
|
|
34
|
+
complexity: number;
|
|
35
|
+
/** Human-readable reasoning for the selection */
|
|
36
|
+
reasoning: string;
|
|
37
|
+
/** Alternative models in priority order */
|
|
38
|
+
fallbackModels: string[];
|
|
39
|
+
/** Whether the selected model is free */
|
|
40
|
+
isFree: boolean;
|
|
41
|
+
/** Whether this is classified as an expert-level query */
|
|
42
|
+
isExpert: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface QueryFeatures {
|
|
45
|
+
complexity: number;
|
|
46
|
+
length: number;
|
|
47
|
+
has_code: boolean;
|
|
48
|
+
has_math: boolean;
|
|
49
|
+
is_multilingual: boolean;
|
|
50
|
+
is_translation: boolean;
|
|
51
|
+
is_creative: boolean;
|
|
52
|
+
requires_reasoning: boolean;
|
|
53
|
+
is_security: boolean;
|
|
54
|
+
is_devops: boolean;
|
|
55
|
+
is_data: boolean;
|
|
56
|
+
detected_domain: string;
|
|
57
|
+
domain_score: number;
|
|
58
|
+
}
|
|
59
|
+
export interface A3MRouterConfig {
|
|
60
|
+
/** Default model to use when routing is ambiguous */
|
|
61
|
+
defaultModel?: string;
|
|
62
|
+
/** Maximum cost per query in USD (routes to cheaper models if exceeded) */
|
|
63
|
+
maxCostPerQuery?: number;
|
|
64
|
+
/** Prefer fast responses over higher quality */
|
|
65
|
+
preferSpeedOverQuality?: boolean;
|
|
66
|
+
/** Restrict routing to these provider IDs */
|
|
67
|
+
providers?: string[];
|
|
68
|
+
}
|
|
69
|
+
export declare class A3MRouter {
|
|
70
|
+
private config;
|
|
71
|
+
private _proxyURL;
|
|
72
|
+
constructor(config?: A3MRouterConfig);
|
|
73
|
+
/**
|
|
74
|
+
* Route a query — returns model selection without executing it.
|
|
75
|
+
*
|
|
76
|
+
* @param query - The user prompt to route
|
|
77
|
+
* @returns Routing decision with model, tier, cost, complexity
|
|
78
|
+
*/
|
|
79
|
+
route(query: string): RoutingResult;
|
|
80
|
+
/**
|
|
81
|
+
* Route multiple queries in batch.
|
|
82
|
+
*
|
|
83
|
+
* @param queries - Array of user prompts
|
|
84
|
+
* @returns Array of routing decisions
|
|
85
|
+
*/
|
|
86
|
+
routeBatch(queries: string[]): RoutingResult[];
|
|
87
|
+
/**
|
|
88
|
+
* Get model recommendation for a task description.
|
|
89
|
+
*
|
|
90
|
+
* @param task - Task description (e.g. "code generation", "summarization")
|
|
91
|
+
* @returns Routing decision
|
|
92
|
+
*/
|
|
93
|
+
recommend(task: string): RoutingResult;
|
|
94
|
+
/**
|
|
95
|
+
* Start the OpenAI-compatible proxy server.
|
|
96
|
+
*
|
|
97
|
+
* @param port - Port to listen on (default: 8787)
|
|
98
|
+
* @returns The proxy base URL (e.g. "http://localhost:8787/v1")
|
|
99
|
+
*/
|
|
100
|
+
serve(port?: number): Promise<string>;
|
|
101
|
+
/**
|
|
102
|
+
* Get the proxy URL. Available after serve() is called,
|
|
103
|
+
* otherwise returns the default.
|
|
104
|
+
*/
|
|
105
|
+
get proxyURL(): string;
|
|
106
|
+
/**
|
|
107
|
+
* Extract features from a query for debugging or analysis.
|
|
108
|
+
*
|
|
109
|
+
* @param query - The user prompt to analyze
|
|
110
|
+
* @returns Detailed feature breakdown
|
|
111
|
+
*/
|
|
112
|
+
analyze(query: string): QueryFeatures;
|
|
113
|
+
/**
|
|
114
|
+
* Classify a complexity score into a named tier.
|
|
115
|
+
*/
|
|
116
|
+
private classifyTier;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Convenience: create an A3MRouter instance.
|
|
120
|
+
*
|
|
121
|
+
* @param config - Optional configuration
|
|
122
|
+
* @returns Configured A3MRouter instance
|
|
123
|
+
*/
|
|
124
|
+
export declare function createSDK(config?: A3MRouterConfig): A3MRouter;
|
|
125
|
+
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../src/sdk.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAcH,MAAM,WAAW,aAAa;IAC5B,sEAAsE;IACtE,KAAK,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,KAAK,GAAG,SAAS,CAAC;IAC3C,4BAA4B;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,iDAAiD;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,yCAAyC;IACzC,MAAM,EAAE,OAAO,CAAC;IAChB,0DAA0D;IAC1D,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,EAAE,OAAO,CAAC;IACrB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,WAAW,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,OAAO,CAA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