adaptive-memory-multi-model-router 2.2.6 → 2.2.8
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 +146 -105
- 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/analytics/costAnalytics.d.ts +0 -1
- package/dist/cache/semanticCache.d.ts +0 -41
- package/dist/cache/semanticCache.d.ts.map +1 -1
- package/dist/cache/semanticCache.js +0 -142
- package/dist/cache/semanticCache.js.map +1 -1
- package/dist/cli.js +478 -35
- package/dist/cost/costTracker.js +3 -0
- package/dist/index.d.ts +0 -16
- package/dist/index.js +64 -264
- package/dist/integrations/langchainAdapter.d.ts +0 -1
- package/dist/integrations/oauth.d.ts +0 -1
- package/dist/memory/autoFetch.d.ts +0 -1
- package/dist/memory/memoryTree.d.ts +0 -1
- package/dist/memory/obsidianVault.d.ts +0 -1
- package/dist/providers/providerConfig.d.ts +0 -1
- package/dist/providers/providerConfig.js +0 -2
- package/dist/providers/registry.js +128 -126
- package/dist/routing/advancedRouter.js +427 -310
- package/dist/sdk.js +100 -109
- package/dist/security/guardrails.d.ts +0 -1
- package/dist/server/dashboard.d.ts +0 -1
- package/dist/server/modelMapper.d.ts +0 -1
- package/dist/server/proxyServer.d.ts +0 -1
- package/package.json +96 -389
- package/scripts/run-mmlu-benchmark.js +176 -0
- package/scripts/run-provider-benchmark.js +244 -0
- package/src/cache/semanticCache.ts +0 -148
- package/src/index.ts +99 -0
- package/test/provider-test.js +70 -91
- package/test.js +41 -67
- package/tsconfig.json +5 -15
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/sdk.d.ts.map +0 -1
- package/dist/sdk.js.map +0 -1
- package/test.js.bak +0 -376
package/dist/sdk.js
CHANGED
|
@@ -5,127 +5,118 @@
|
|
|
5
5
|
* Clean wrapper class providing a better DX than raw exports.
|
|
6
6
|
*
|
|
7
7
|
* Usage:
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* const { A3MRouter } = require('adaptive-memory-multi-model-router/sdk');
|
|
10
9
|
* const router = new A3MRouter();
|
|
11
|
-
*
|
|
12
|
-
* // Route a query (no execution, just model selection)
|
|
13
10
|
* const decision = router.route("What is 2+2?");
|
|
14
11
|
* console.log(decision.model, decision.tier, decision.cost);
|
|
15
|
-
*
|
|
16
|
-
* // Start the OpenAI-compatible proxy server
|
|
17
|
-
* const proxyURL = await router.serve(8787);
|
|
18
|
-
*
|
|
19
|
-
* // Use with any OpenAI SDK
|
|
20
|
-
* import OpenAI from 'openai';
|
|
21
|
-
* const client = new OpenAI({ baseURL: router.proxyURL });
|
|
22
|
-
* const response = await client.chat.completions.create({
|
|
23
|
-
* model: 'auto',
|
|
24
|
-
* messages: [{ role: 'user', content: 'Hello' }]
|
|
25
|
-
* });
|
|
26
12
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const proxyServer_1 = require("./server/proxyServer");
|
|
13
|
+
|
|
14
|
+
const advancedRouter = require("./routing/advancedRouter");
|
|
15
|
+
const proxyServer = require("./server/proxyServer");
|
|
16
|
+
|
|
32
17
|
// ============================================================
|
|
33
18
|
// A3MRouter SDK Class
|
|
34
19
|
// ============================================================
|
|
20
|
+
|
|
35
21
|
class A3MRouter {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
22
|
+
constructor(config = {}) {
|
|
23
|
+
this.config = config;
|
|
24
|
+
this._proxyURL = null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Route a query — returns model selection without executing it.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} query - The user prompt to route
|
|
31
|
+
* @returns {object} Routing decision with model, tier, cost, complexity
|
|
32
|
+
*/
|
|
33
|
+
route(query) {
|
|
34
|
+
const features = advancedRouter.extractQueryFeatures(query);
|
|
35
|
+
const result = advancedRouter.routeQuery(query, this.config.providers);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
model: result.primary_model || 'unknown',
|
|
39
|
+
tier: this.classifyTier(features.complexity),
|
|
40
|
+
cost: result.estimated_cost || 0,
|
|
41
|
+
complexity: features.complexity,
|
|
42
|
+
reasoning: result.reasoning || '',
|
|
43
|
+
fallbackModels: result.fallback_models || [],
|
|
44
|
+
isFree: (result.estimated_cost || 0) === 0,
|
|
45
|
+
isExpert: features.complexity >= 0.65,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Route multiple queries in batch.
|
|
51
|
+
*
|
|
52
|
+
* @param {string[]} queries - Array of user prompts
|
|
53
|
+
* @returns {object[]} Array of routing decisions
|
|
54
|
+
*/
|
|
55
|
+
routeBatch(queries) {
|
|
56
|
+
advancedRouter.routeBatch(queries); // warm the internal cache
|
|
57
|
+
return queries.map((q) => this.route(q));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Get model recommendation for a task description.
|
|
62
|
+
*
|
|
63
|
+
* @param {string} task - Task description
|
|
64
|
+
* @returns {object} Routing decision
|
|
65
|
+
*/
|
|
66
|
+
recommend(task) {
|
|
67
|
+
advancedRouter.recommendForTask(task);
|
|
68
|
+
return this.route(task);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Start the OpenAI-compatible proxy server.
|
|
73
|
+
*
|
|
74
|
+
* @param {number} port - Port to listen on (default: 8787)
|
|
75
|
+
* @returns {Promise<string>} The proxy base URL
|
|
76
|
+
*/
|
|
77
|
+
async serve(port = 8787) {
|
|
78
|
+
proxyServer.createProxyServer(port);
|
|
79
|
+
this._proxyURL = `http://localhost:${port}/v1`;
|
|
80
|
+
return this._proxyURL;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Get the proxy URL. Available after serve() is called.
|
|
85
|
+
*/
|
|
86
|
+
get proxyURL() {
|
|
87
|
+
return this._proxyURL || 'http://localhost:8787/v1';
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Extract features from a query for debugging or analysis.
|
|
92
|
+
*
|
|
93
|
+
* @param {string} query - The user prompt to analyze
|
|
94
|
+
* @returns {object} Detailed feature breakdown
|
|
95
|
+
*/
|
|
96
|
+
analyze(query) {
|
|
97
|
+
return advancedRouter.extractQueryFeatures(query);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Classify a complexity score into a named tier.
|
|
102
|
+
*/
|
|
103
|
+
classifyTier(complexity) {
|
|
104
|
+
if (complexity < 0.20) return 'free';
|
|
105
|
+
if (complexity < 0.45) return 'cheap';
|
|
106
|
+
if (complexity < 0.65) return 'mid';
|
|
107
|
+
return 'premium';
|
|
108
|
+
}
|
|
120
109
|
}
|
|
121
|
-
|
|
110
|
+
|
|
122
111
|
/**
|
|
123
112
|
* Convenience: create an A3MRouter instance.
|
|
124
113
|
*
|
|
125
|
-
* @param config - Optional configuration
|
|
126
|
-
* @returns Configured
|
|
114
|
+
* @param {object} config - Optional configuration
|
|
115
|
+
* @returns {A3MRouter} Configured instance
|
|
127
116
|
*/
|
|
128
117
|
function createSDK(config) {
|
|
129
|
-
|
|
118
|
+
return new A3MRouter(config);
|
|
130
119
|
}
|
|
131
|
-
|
|
120
|
+
|
|
121
|
+
module.exports = { A3MRouter, createSDK };
|
|
122
|
+
module.exports.default = A3MRouter;
|
|
@@ -56,4 +56,3 @@ export declare function registerProvider(id: string, name: string): void;
|
|
|
56
56
|
*/
|
|
57
57
|
export declare function handleDashboardRequest(req: http.IncomingMessage, res: http.ServerResponse): boolean;
|
|
58
58
|
export declare function getDashboardHTML(): string;
|
|
59
|
-
//# sourceMappingURL=dashboard.d.ts.map
|