adaptive-memory-multi-model-router 2.13.23 β 2.13.25
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/.github/workflows/stale.yml +1 -1
- package/README.md +7 -5
- package/dist/tui/dashboard.js +12 -0
- package/dist/tui/dashboard.js.map +1 -1
- package/dist/utils/tokenUtils.d.ts +3 -48
- package/dist/utils/tokenUtils.js +8 -115
- package/dist/utils/tokenUtils.js.map +1 -1
- package/docs/npm-downloads-chart.svg +43 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
[π¨π³ δΈζ](./README_zh.md) Β· [π―π΅ ζ₯ζ¬θͺ](./README_ja.md) Β· [English](./README.md)
|
|
2
2
|
|
|
3
|
-
# A3M Router π β
|
|
3
|
+
# A3M Router π β π₯ #1 on RouterArena Β· Cheapest at $0.047/1K Queries
|
|
4
|
+
|
|
5
|
+
**The highest-ranked and lowest-cost LLM router on the [RouterArena leaderboard](https://github.com/RouteWorks/RouterArena/pull/113).**
|
|
4
6
|
|
|
5
7
|
[](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
|
|
6
8
|
[](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
|
|
9
|
+
[](https://github.com/RouteWorks/RouterArena/pull/113)
|
|
7
10
|
[](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
|
|
8
11
|
[](https://github.com/Das-rebel/a3m-router)
|
|
9
12
|
[](https://github.com/Das-rebel/a3m-router/actions)
|
|
10
|
-
[](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
|
|
11
13
|
[](./LICENSE)
|
|
12
14
|
|
|
13
15
|
## π Growth
|
|
14
16
|
|
|
15
|
-
[](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
|
|
16
18
|
|
|
17
|
-
> **The
|
|
19
|
+
> **The highest-ranked and lowest-cost LLM router on the RouterArena leaderboard** β #1 (76.43), cheapest at $0.047/1K queries. Parallel multi-LLM execution across 47+ providers. Open-source, 19.5KB, zero ML dependencies.
|
|
18
20
|
|
|
19
21
|
**One prompt in. The right model out.** An open-source **AI gateway** that auto-routes every query to the cheapest capable model across **47+ LLM providers**. Features **parallel ensemble execution**, **semantic cache**, **budget enforcement**, **intelligent failover**, and **independent benchmark validation**. Start in <100ms. Python SDK + TypeScript SDK.
|
|
20
22
|
|
|
@@ -30,7 +32,7 @@
|
|
|
30
32
|
node dist/tui/dashboard.js
|
|
31
33
|
```
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
Terminal overlay box with `/route`, `/cost`, `/health`, `/models`, `/model <provider>`. Type anything to auto-route through the cheapest model.
|
|
34
36
|
|
|
35
37
|
### π By the Numbers
|
|
36
38
|
|
package/dist/tui/dashboard.js
CHANGED
|
@@ -37,6 +37,18 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
37
37
|
};
|
|
38
38
|
})();
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
// ββ Banner ββ
|
|
41
|
+
console.log(`
|
|
42
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
43
|
+
β ββββββββββββ β
|
|
44
|
+
β β ββ£β βββββ β β
|
|
45
|
+
β β© β©βββββββββ β
|
|
46
|
+
β β
|
|
47
|
+
β Parallel Multi-LLM Execution Engine β
|
|
48
|
+
β β
|
|
49
|
+
β 47+ Providers Β· Ensemble Voting Β· 62% Cost Savings β
|
|
50
|
+
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
51
|
+
`);
|
|
40
52
|
const blessed = __importStar(require("blessed"));
|
|
41
53
|
// ββ State ββ
|
|
42
54
|
let activeModel = 'nvidia/llama-3.1-8b';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dashboard.js","sourceRoot":"","sources":["../../src/tui/dashboard.ts"],"names":[],"mappings":";;AACA;;GAEG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,iD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|
4
|
-
* Token counting, cost estimation, and context management.
|
|
2
|
+
* Token counting utilities for provider cost estimation
|
|
5
3
|
*/
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
output_per_1k: number;
|
|
9
|
-
}
|
|
10
|
-
export declare const MODEL_COSTS: Record<string, TokenCost>;
|
|
11
|
-
/**
|
|
12
|
-
* Count tokens in text (approximate for English).
|
|
13
|
-
* Based on ~1.3 tokens per word for typical English text.
|
|
14
|
-
*/
|
|
15
|
-
export declare function countTokens(text: string, model?: string): number;
|
|
16
|
-
/**
|
|
17
|
-
* Estimate cost for a prompt/completion pair.
|
|
18
|
-
*/
|
|
19
|
-
export declare function estimateCost(prompt_tokens: number, completion_tokens: number, model: string): number;
|
|
20
|
-
/**
|
|
21
|
-
* Estimate cost from raw text (approximates both prompt and completion).
|
|
22
|
-
*/
|
|
23
|
-
export declare function estimateCostFromText(prompt: string, completion: string, model: string): number;
|
|
24
|
-
/**
|
|
25
|
-
* Get cost info for a model.
|
|
26
|
-
*/
|
|
27
|
-
export declare function getModelCost(model: string): TokenCost;
|
|
28
|
-
/**
|
|
29
|
-
* List all supported models with their costs.
|
|
30
|
-
*/
|
|
31
|
-
export declare function listModelsByCost(): Array<{
|
|
32
|
-
model: string;
|
|
33
|
-
input: number;
|
|
34
|
-
output: number;
|
|
35
|
-
}>;
|
|
36
|
-
/**
|
|
37
|
-
* Find cheapest models for a given task.
|
|
38
|
-
*/
|
|
39
|
-
export declare function findCheapestModels(task: "fast" | "quality" | "balanced" | "coding", count?: number): string[];
|
|
40
|
-
declare const _default: {
|
|
41
|
-
countTokens: typeof countTokens;
|
|
42
|
-
estimateCost: typeof estimateCost;
|
|
43
|
-
estimateCostFromText: typeof estimateCostFromText;
|
|
44
|
-
getModelCost: typeof getModelCost;
|
|
45
|
-
listModelsByCost: typeof listModelsByCost;
|
|
46
|
-
findCheapestModels: typeof findCheapestModels;
|
|
47
|
-
MODEL_COSTS: Record<string, TokenCost>;
|
|
48
|
-
};
|
|
49
|
-
export default _default;
|
|
50
|
-
//# sourceMappingURL=tokenUtils.d.ts.map
|
|
4
|
+
export declare function countTokens(text: string): number;
|
|
5
|
+
export declare function estimateTokens(text: string): number;
|
package/dist/utils/tokenUtils.js
CHANGED
|
@@ -1,124 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* Token counting, cost estimation, and context management.
|
|
3
|
+
* Token counting utilities for provider cost estimation
|
|
6
4
|
*/
|
|
7
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.MODEL_COSTS = void 0;
|
|
9
6
|
exports.countTokens = countTokens;
|
|
10
|
-
exports.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
exports.listModelsByCost = listModelsByCost;
|
|
14
|
-
exports.findCheapestModels = findCheapestModels;
|
|
15
|
-
// Current provider rates (2024-2025)
|
|
16
|
-
exports.MODEL_COSTS = {
|
|
17
|
-
// OpenAI
|
|
18
|
-
"gpt-4o": { input_per_1k: 2.50, output_per_1k: 10.00 },
|
|
19
|
-
"gpt-4o-mini": { input_per_1k: 0.15, output_per_1k: 0.60 },
|
|
20
|
-
"gpt-4-turbo": { input_per_1k: 10.00, output_per_1k: 30.00 },
|
|
21
|
-
"gpt-3.5-turbo": { input_per_1k: 0.50, output_per_1k: 1.50 },
|
|
22
|
-
// Anthropic
|
|
23
|
-
"claude-3.5-sonnet": { input_per_1k: 3.00, output_per_1k: 15.00 },
|
|
24
|
-
"claude-3-opus": { input_per_1k: 15.00, output_per_1k: 75.00 },
|
|
25
|
-
"claude-3-haiku": { input_per_1k: 0.25, output_per_1k: 1.25 },
|
|
26
|
-
// Google
|
|
27
|
-
"gemini-2.0-flash": { input_per_1k: 0.00, output_per_1k: 0.00 }, // Free
|
|
28
|
-
"gemini-1.5-pro": { input_per_1k: 1.25, output_per_1k: 5.00 },
|
|
29
|
-
"gemini-1.5-flash": { input_per_1k: 0.075, output_per_1k: 0.30 },
|
|
30
|
-
// Groq
|
|
31
|
-
"groq/llama-3.3-70b": { input_per_1k: 0.59, output_per_1k: 0.79 },
|
|
32
|
-
"groq/llama-3.1-8b": { input_per_1k: 0.05, output_per_1k: 0.08 },
|
|
33
|
-
// Cerebras
|
|
34
|
-
"cerebras/llama-3.3-70b": { input_per_1k: 0.60, output_per_1k: 0.60 },
|
|
35
|
-
// Mistral
|
|
36
|
-
"mistral-large": { input_per_1k: 2.00, output_per_1k: 6.00 },
|
|
37
|
-
"mistral-small": { input_per_1k: 0.20, output_per_1k: 0.60 },
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Count tokens in text (approximate for English).
|
|
41
|
-
* Based on ~1.3 tokens per word for typical English text.
|
|
42
|
-
*/
|
|
43
|
-
function countTokens(text, model = "gpt-4o") {
|
|
44
|
-
if (!text || text.length === 0)
|
|
7
|
+
exports.estimateTokens = estimateTokens;
|
|
8
|
+
function countTokens(text) {
|
|
9
|
+
if (!text)
|
|
45
10
|
return 0;
|
|
46
|
-
//
|
|
47
|
-
|
|
48
|
-
const words = text.trim().split(/\s+/).length;
|
|
49
|
-
// Fine-tune based on model family
|
|
50
|
-
if (model.includes("claude")) {
|
|
51
|
-
// Anthropic models: ~1.5 tokens per word
|
|
52
|
-
return Math.ceil(words * 1.5);
|
|
53
|
-
}
|
|
54
|
-
else if (model.includes("gemini")) {
|
|
55
|
-
// Google: ~1.2 tokens per word (SentencePiece)
|
|
56
|
-
return Math.ceil(words * 1.2);
|
|
57
|
-
}
|
|
58
|
-
else if (model.includes("llama")) {
|
|
59
|
-
// Llama: ~1.4 tokens per word (BPE)
|
|
60
|
-
return Math.ceil(words * 1.4);
|
|
61
|
-
}
|
|
62
|
-
// Default: ~1.3 tokens per word (GPT-4 average)
|
|
63
|
-
return Math.ceil(words * 1.3);
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Estimate cost for a prompt/completion pair.
|
|
67
|
-
*/
|
|
68
|
-
function estimateCost(prompt_tokens, completion_tokens, model) {
|
|
69
|
-
const costs = exports.MODEL_COSTS[model] || exports.MODEL_COSTS["gpt-4o"];
|
|
70
|
-
const input_cost = (prompt_tokens / 1000) * costs.input_per_1k;
|
|
71
|
-
const output_cost = (completion_tokens / 1000) * costs.output_per_1k;
|
|
72
|
-
return input_cost + output_cost;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Estimate cost from raw text (approximates both prompt and completion).
|
|
76
|
-
*/
|
|
77
|
-
function estimateCostFromText(prompt, completion, model) {
|
|
78
|
-
const prompt_tokens = countTokens(prompt, model);
|
|
79
|
-
// Completion typically has higher token density
|
|
80
|
-
const completion_tokens = Math.ceil(countTokens(completion, model) * 1.2);
|
|
81
|
-
return estimateCost(prompt_tokens, completion_tokens, model);
|
|
11
|
+
// Rough estimate: ~4 chars per token for English text
|
|
12
|
+
return Math.ceil(text.length / 4);
|
|
82
13
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
*/
|
|
86
|
-
function getModelCost(model) {
|
|
87
|
-
return exports.MODEL_COSTS[model] || exports.MODEL_COSTS["gpt-4o"];
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* List all supported models with their costs.
|
|
91
|
-
*/
|
|
92
|
-
function listModelsByCost() {
|
|
93
|
-
return Object.entries(exports.MODEL_COSTS)
|
|
94
|
-
.map(([model, cost]) => ({
|
|
95
|
-
model,
|
|
96
|
-
input: cost.input_per_1k,
|
|
97
|
-
output: cost.output_per_1k
|
|
98
|
-
}))
|
|
99
|
-
.sort((a, b) => (a.input + a.output) - (b.input + b.output));
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Find cheapest models for a given task.
|
|
103
|
-
*/
|
|
104
|
-
function findCheapestModels(task, count = 3) {
|
|
105
|
-
const sorted = listModelsByCost();
|
|
106
|
-
// Different profiles for different needs
|
|
107
|
-
const profiles = {
|
|
108
|
-
fast: sorted.filter(m => m.output < 1.0).slice(0, count).map(m => m.model),
|
|
109
|
-
quality: sorted.filter(m => m.output > 10).slice(0, count).map(m => m.model),
|
|
110
|
-
balanced: sorted.slice(0, count * 2).slice(count, count * 2).map(m => m.model),
|
|
111
|
-
coding: sorted.filter(m => m.model.includes("codex") || m.model.includes("claude") || m.model.includes("llama")).slice(0, count).map(m => m.model)
|
|
112
|
-
};
|
|
113
|
-
return profiles[task] || profiles.balanced;
|
|
14
|
+
function estimateTokens(text) {
|
|
15
|
+
return countTokens(text);
|
|
114
16
|
}
|
|
115
|
-
exports.default = {
|
|
116
|
-
countTokens,
|
|
117
|
-
estimateCost,
|
|
118
|
-
estimateCostFromText,
|
|
119
|
-
getModelCost,
|
|
120
|
-
listModelsByCost,
|
|
121
|
-
findCheapestModels,
|
|
122
|
-
MODEL_COSTS: exports.MODEL_COSTS
|
|
123
|
-
};
|
|
124
17
|
//# sourceMappingURL=tokenUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenUtils.js","sourceRoot":"","sources":["../../src/utils/tokenUtils.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"tokenUtils.js","sourceRoot":"","sources":["../../src/utils/tokenUtils.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAEH,kCAIC;AAED,wCAEC;AARD,SAAgB,WAAW,CAAC,IAAY;IACtC,IAAI,CAAC,IAAI;QAAE,OAAO,CAAC,CAAC;IACpB,sDAAsD;IACtD,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,SAAgB,cAAc,CAAC,IAAY;IACzC,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;AAC3B,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="800" height="300" viewBox="0 0 800 300">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="bg" x1="0" y1="0" x2="0" y2="1">
|
|
4
|
+
<stop offset="0%" stop-color="#1a1a2e"/>
|
|
5
|
+
<stop offset="100%" stop-color="#16213e"/>
|
|
6
|
+
</linearGradient>
|
|
7
|
+
<linearGradient id="lineGrad" x1="0" y1="0" x2="1" y2="0">
|
|
8
|
+
<stop offset="0%" stop-color="#4fc3f7"/>
|
|
9
|
+
<stop offset="100%" stop-color="#00e676"/>
|
|
10
|
+
</linearGradient>
|
|
11
|
+
<linearGradient id="areaGrad" x1="0" y1="0" x2="0" y2="1">
|
|
12
|
+
<stop offset="0%" stop-color="#4fc3f7" stop-opacity="0.3"/>
|
|
13
|
+
<stop offset="100%" stop-color="#4fc3f7" stop-opacity="0.02"/>
|
|
14
|
+
</linearGradient>
|
|
15
|
+
</defs>
|
|
16
|
+
|
|
17
|
+
<rect width="800" height="300" fill="url(#bg)" rx="12"/>
|
|
18
|
+
|
|
19
|
+
<text x="400.0" y="30" text-anchor="middle" fill="#e0e0e0" font-family="monospace" font-size="16" font-weight="bold">npm Downloads</text>
|
|
20
|
+
<text x="400.0" y="50" text-anchor="middle" fill="#90a4ae" font-family="monospace" font-size="11">Total: 11,637 Β· v2.13.24 Β· π₯ RouterArena #1 (76.43) Β· Cheapest at $0.047/1K</text>
|
|
21
|
+
<line x1="60" y1="60.0" x2="740" y2="60.0" stroke="#2a2a4e" stroke-width="1"/>
|
|
22
|
+
<text x="52" y="64.0" text-anchor="end" fill="#90a4ae" font-family="monospace" font-size="10">11,637</text>
|
|
23
|
+
<line x1="60" y1="105.0" x2="740" y2="105.0" stroke="#2a2a4e" stroke-width="1"/>
|
|
24
|
+
<text x="52" y="109.0" text-anchor="end" fill="#90a4ae" font-family="monospace" font-size="10">8,727</text>
|
|
25
|
+
<line x1="60" y1="150.0" x2="740" y2="150.0" stroke="#2a2a4e" stroke-width="1"/>
|
|
26
|
+
<text x="52" y="154.0" text-anchor="end" fill="#90a4ae" font-family="monospace" font-size="10">5,818</text>
|
|
27
|
+
<line x1="60" y1="195.0" x2="740" y2="195.0" stroke="#2a2a4e" stroke-width="1"/>
|
|
28
|
+
<text x="52" y="199.0" text-anchor="end" fill="#90a4ae" font-family="monospace" font-size="10">2,909</text>
|
|
29
|
+
<line x1="60" y1="240.0" x2="740" y2="240.0" stroke="#2a2a4e" stroke-width="1"/>
|
|
30
|
+
<text x="52" y="244.0" text-anchor="end" fill="#90a4ae" font-family="monospace" font-size="10">0</text>
|
|
31
|
+
<text x="60.0" y="258" text-anchor="middle" fill="#90a4ae" font-family="monospace" font-size="9">05-13</text>
|
|
32
|
+
<text x="157.14285714285714" y="258" text-anchor="middle" fill="#90a4ae" font-family="monospace" font-size="9">05-15</text>
|
|
33
|
+
<text x="254.28571428571428" y="258" text-anchor="middle" fill="#90a4ae" font-family="monospace" font-size="9">05-17</text>
|
|
34
|
+
<text x="351.4285714285714" y="258" text-anchor="middle" fill="#90a4ae" font-family="monospace" font-size="9">05-19</text>
|
|
35
|
+
<text x="448.57142857142856" y="258" text-anchor="middle" fill="#90a4ae" font-family="monospace" font-size="9">05-21</text>
|
|
36
|
+
<text x="545.7142857142858" y="258" text-anchor="middle" fill="#90a4ae" font-family="monospace" font-size="9">05-23</text>
|
|
37
|
+
<text x="642.8571428571428" y="258" text-anchor="middle" fill="#90a4ae" font-family="monospace" font-size="9">05-25</text>
|
|
38
|
+
<text x="740.0" y="258" text-anchor="middle" fill="#90a4ae" font-family="monospace" font-size="9">05-27</text>
|
|
39
|
+
<polygon points="60,240 60.0,240.0 108.6,240.0 157.1,231.5 205.7,226.5 254.3,197.1 302.9,174.7 351.4,168.0 400.0,165.2 448.6,145.6 497.1,114.9 545.7,112.2 594.3,109.0 642.9,100.9 691.4,84.9 740.0,60.0 740.0,240" fill="url(#areaGrad)"/>
|
|
40
|
+
<polyline points="60.0,240.0 108.6,240.0 157.1,231.5 205.7,226.5 254.3,197.1 302.9,174.7 351.4,168.0 400.0,165.2 448.6,145.6 497.1,114.9 545.7,112.2 594.3,109.0 642.9,100.9 691.4,84.9 740.0,60.0" fill="none" stroke="url(#lineGrad)" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"/>
|
|
41
|
+
<circle cx="740.0" cy="60.0" r="4" fill="#00e676"/>
|
|
42
|
+
<text x="748.0" y="64.0" fill="#00e676" font-family="monospace" font-size="11" font-weight="bold">11,637 total</text>
|
|
43
|
+
</svg>
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "adaptive-memory-multi-model-router",
|
|
3
|
-
"version": "2.13.
|
|
3
|
+
"version": "2.13.25",
|
|
4
4
|
"shortName": "A3M Router",
|
|
5
5
|
"displayName": "A3M Router - Adaptive Memory Multi-Model Router",
|
|
6
|
-
"description": "
|
|
6
|
+
"description": "π₯ #1 on RouterArena (76.43) Β· Cheapest LLM router at $0.047/1K Β· Open-source AI gateway with parallel multi-LLM execution across 47+ providers, ensemble voting, semantic cache, and budget enforcement",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"bin": {
|
|
9
9
|
"a3m-router": "dist/cli.js",
|