adaptive-memory-multi-model-router 2.0.0 → 2.0.2
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 +96 -255
- package/articles/DEVTO_V2_ANNOUNCEMENT.md +160 -0
- package/articles/DEVTO_VIRAL_GROWTH.md +280 -0
- package/assets/feature-matrix.svg +136 -0
- package/assets/growth-chart.svg +82 -0
- package/assets/provider-comparison.svg +121 -0
- package/dist/index.d.ts +28 -1
- package/dist/index.js +75 -3
- package/dist/index.js.map +1 -1
- package/llms.txt +30 -120
- package/package.json +1 -1
- package/src/index.ts +95 -2
package/README.md
CHANGED
|
@@ -1,326 +1,167 @@
|
|
|
1
|
-
|
|
2
|
-
<img src="assets/banner.svg" alt="A3M Router Banner" width="100%">
|
|
3
|
-
</p>
|
|
1
|
+
# A3M Router 🔀
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
> Intelligent LLM routing engine — **2,775 downloads in 3 days**
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
[](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
|
|
10
|
-
[](https://github.com/Das-rebel/adaptive-memory-multi-model-router/actions)
|
|
11
|
-
[](LICENSE)
|
|
5
|
+
[](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
|
|
6
|
+
[](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
|
|
12
7
|
|
|
13
|
-
|
|
14
|
-
[](docs/providers.md)
|
|
15
|
-
[](docs/integrations.md)
|
|
16
|
-
[](package.json)
|
|
17
|
-
[](https://bundlephobia.com/package/adaptive-memory-multi-model-router)
|
|
18
|
-
|
|
19
|
-
</div>
|
|
8
|
+
**Zero marketing budget. 1,903 downloads yesterday alone.**
|
|
20
9
|
|
|
21
10
|
---
|
|
22
11
|
|
|
23
|
-
|
|
24
|
-
<b>Route LLM queries to optimal providers automatically</b>
|
|
25
|
-
</h3>
|
|
26
|
-
|
|
27
|
-
<p align="center">
|
|
28
|
-
Save <b>50-80%</b> on API costs • <b>5-10x</b> speedups • <b>Zero</b> configuration needed
|
|
29
|
-
</p>
|
|
30
|
-
|
|
31
|
-
<div align="center">
|
|
32
|
-
|
|
33
|
-
[📖 Documentation](https://github.com/Das-rebel/adaptive-memory-multi-model-router#readme) •
|
|
34
|
-
[🚀 Quick Start](#quick-start) •
|
|
35
|
-
[🎮 Try Online](https://codesandbox.io/p/sandbox/github/Das-rebel/adaptive-memory-multi-model-router/tree/main/playground) •
|
|
36
|
-
[📊 Benchmarks](#benchmarks) •
|
|
37
|
-
[🤝 Contributing](CONTRIBUTING.md) •
|
|
38
|
-
[💬 Discussions](https://github.com/Das-rebel/adaptive-memory-multi-model-router/discussions)
|
|
12
|
+
## Why People Are Switching
|
|
39
13
|
|
|
40
|
-
|
|
14
|
+
**The Problem:** You're sending every query to GPT-4 at $30/1M tokens. But 47% of your queries are simple Q&A that a free provider handles perfectly.
|
|
41
15
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
[](https://codesandbox.io/p/sandbox/github/Das-rebel/adaptive-memory-multi-model-router/tree/main/playground)
|
|
45
|
-
[](https://stackblitz.com/github/Das-rebel/adaptive-memory-multi-model-router/tree/main/playground)
|
|
46
|
-
|
|
47
|
-
</div>
|
|
16
|
+
**The Solution:** A3M Router analyzes each query and routes it to the cheapest capable provider — automatically.
|
|
48
17
|
|
|
49
18
|
---
|
|
50
19
|
|
|
51
|
-
##
|
|
52
|
-
|
|
53
|
-
<table>
|
|
54
|
-
<tr>
|
|
55
|
-
<td width="50%">
|
|
56
|
-
|
|
57
|
-
### 🧠 Learned Routing
|
|
58
|
-
Routes queries based on **actual query characteristics** - not just random selection. Code queries go to code-capable models. Simple queries use cheaper providers.
|
|
59
|
-
|
|
60
|
-
</td>
|
|
61
|
-
<td width="50%">
|
|
62
|
-
|
|
63
|
-
### 💰 Cost Optimization
|
|
64
|
-
Automatically selects the **cheapest capable provider**. Route simple queries to free tiers. Use premium models only when complexity demands it.
|
|
65
|
-
|
|
66
|
-
</td>
|
|
67
|
-
</tr>
|
|
68
|
-
<tr>
|
|
69
|
-
<td width="50%">
|
|
70
|
-
|
|
71
|
-
### 🔄 Smart Fallback
|
|
72
|
-
When a provider fails, **automatically retry** with the next best option. No manual intervention needed. Your app stays resilient.
|
|
73
|
-
|
|
74
|
-
</td>
|
|
75
|
-
<td width="50%">
|
|
20
|
+
## The Numbers
|
|
76
21
|
|
|
77
|
-
|
|
78
|
-
|
|
22
|
+
| Provider | Cost / 1M tokens | Speed | Quality |
|
|
23
|
+
|----------|:-----------------:|:-----:|:-------:|
|
|
24
|
+
| CommandCode | **$0.00** | 5s | 75% |
|
|
25
|
+
| Groq | **$0.59** | 420ms | 82% |
|
|
26
|
+
| Cerebras | **$0.60** | 380ms | 82% |
|
|
27
|
+
| Mistral | **$2.00** | 800ms | 90% |
|
|
28
|
+
| OpenAI GPT-4 | $30.00 | 2100ms | 95% |
|
|
79
29
|
|
|
80
|
-
|
|
81
|
-
</tr>
|
|
82
|
-
</table>
|
|
30
|
+
**Route to the right provider = 70% cost savings, 62% faster.**
|
|
83
31
|
|
|
84
|
-
|
|
32
|
+
---
|
|
85
33
|
|
|
86
|
-
|
|
34
|
+
## Quick Start (30 seconds)
|
|
87
35
|
|
|
88
|
-
|
|
89
|
-
[](https://stackblitz.com/github/Das-rebel/adaptive-memory-multi-model-router/tree/main/playground)
|
|
36
|
+
### Option 1: OpenAI-Compatible Proxy
|
|
90
37
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
-
|
|
94
|
-
|
|
95
|
-
- Experiment with no API keys needed!
|
|
38
|
+
```bash
|
|
39
|
+
npm install adaptive-memory-multi-model-router
|
|
40
|
+
npx a3m-router serve
|
|
41
|
+
```
|
|
96
42
|
|
|
97
|
-
|
|
43
|
+
Now point any OpenAI SDK at `http://localhost:8787/v1`:
|
|
98
44
|
|
|
99
|
-
|
|
45
|
+
```python
|
|
46
|
+
from openai import OpenAI
|
|
100
47
|
|
|
101
|
-
|
|
102
|
-
|
|
48
|
+
client = OpenAI(base_url="http://localhost:8787/v1", api_key="not-needed")
|
|
49
|
+
response = client.chat.completions.create(
|
|
50
|
+
model="auto",
|
|
51
|
+
messages=[{"role": "user", "content": "Hello!"}]
|
|
52
|
+
)
|
|
103
53
|
```
|
|
104
54
|
|
|
105
|
-
|
|
55
|
+
Works with **Python, Node, LangChain, LlamaIndex** — any OpenAI-compatible client. Zero code changes.
|
|
56
|
+
|
|
57
|
+
### Option 2: Library
|
|
106
58
|
|
|
107
59
|
```javascript
|
|
108
60
|
const { createA3MRouter } = require('adaptive-memory-multi-model-router');
|
|
109
61
|
|
|
110
62
|
const router = createA3MRouter();
|
|
111
63
|
|
|
112
|
-
//
|
|
113
|
-
const result = await router.route("
|
|
114
|
-
|
|
115
|
-
console.log(result.
|
|
116
|
-
console.log(result.
|
|
64
|
+
// Automatic routing — picks the cheapest capable provider
|
|
65
|
+
const result = await router.route("Explain quantum computing in one paragraph");
|
|
66
|
+
console.log(result.response); // the answer
|
|
67
|
+
console.log(result.provider); // which provider was chosen
|
|
68
|
+
console.log(result.cost); // what it cost
|
|
117
69
|
```
|
|
118
70
|
|
|
119
|
-
### CLI
|
|
71
|
+
### Option 3: CLI
|
|
120
72
|
|
|
121
73
|
```bash
|
|
122
|
-
#
|
|
123
|
-
npx a3m-router
|
|
124
|
-
|
|
125
|
-
# Route a query
|
|
126
|
-
npx a3m-router route "Explain quantum physics"
|
|
74
|
+
# Route a single query
|
|
75
|
+
npx a3m-router route "Your query here"
|
|
127
76
|
|
|
128
77
|
# Benchmark all providers
|
|
129
78
|
npx a3m-router benchmark
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
## 📊 Benchmarks
|
|
133
|
-
|
|
134
|
-
<!-- BENCHMARK_START -->
|
|
135
|
-
| Provider | Latency | Cost/1K | Quality | Best For |
|
|
136
|
-
|----------|---------|---------|---------|----------|
|
|
137
|
-
| **Groq** | 400ms | $0.59 | ⭐⭐⭐⭐ | Fast inference |
|
|
138
|
-
| **Cerebras** | 350ms | $0.60 | ⭐⭐⭐⭐ | Speed-critical |
|
|
139
|
-
| **Mistral** | 800ms | $0.20 | ⭐⭐⭐⭐⭐ | Cost + quality |
|
|
140
|
-
| **CommandCode** | 5s | **FREE** | ⭐⭐⭐ | Budget projects |
|
|
141
|
-
| **OpenCode** | 3s | **FREE** | ⭐⭐⭐ | Multi-model |
|
|
142
79
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
## 🎯 Routing Examples
|
|
147
|
-
|
|
148
|
-
```javascript
|
|
149
|
-
const { routeQuery } = require('adaptive-memory-multi-model-router');
|
|
150
|
-
|
|
151
|
-
// Simple query → cheapest provider (FREE)
|
|
152
|
-
routeQuery("What is 2+2?");
|
|
153
|
-
// → commandcode/taste-1 ($0.00)
|
|
154
|
-
|
|
155
|
-
// Code query → fast, code-capable provider
|
|
156
|
-
routeQuery("Write Python to reverse a string");
|
|
157
|
-
// → groq/llama-3.3-70b ($0.0004)
|
|
158
|
-
|
|
159
|
-
// Complex reasoning → high-quality provider
|
|
160
|
-
routeQuery("Explain quantum entanglement");
|
|
161
|
-
// → mistral/mistral-large ($0.002)
|
|
162
|
-
|
|
163
|
-
// Batch processing with auto-routing
|
|
164
|
-
const queries = ["Q1", "Q2", "Q3"];
|
|
165
|
-
const results = routeBatch(queries);
|
|
166
|
-
```
|
|
167
|
-
|
|
168
|
-
## 🏗️ Architecture
|
|
169
|
-
|
|
170
|
-
```
|
|
171
|
-
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
|
|
172
|
-
│ User Query │────▶│ Feature Extraction │────▶│ Query Analysis │
|
|
173
|
-
└─────────────────┘ └──────────────────┘ └─────────────────┘
|
|
174
|
-
│
|
|
175
|
-
┌───────────────────────────┼───────────────────────────┐
|
|
176
|
-
│ │ │
|
|
177
|
-
▼ ▼ ▼
|
|
178
|
-
┌─────────┐ ┌─────────┐ ┌─────────┐
|
|
179
|
-
│ Code? │ │ Math? │ │ Simple? │
|
|
180
|
-
└────┬────┘ └────┬────┘ └────┬────┘
|
|
181
|
-
│ │ │
|
|
182
|
-
▼ ▼ ▼
|
|
183
|
-
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐ ┌─────────────────┐
|
|
184
|
-
│ Model Profiles │◀────│ Router Engine │────▶│ Cost/Quality │────▶│ Provider Select │
|
|
185
|
-
│ (12 providers) │ │ (Learned algo) │ │ Tradeoff │ │ + Fallback │
|
|
186
|
-
└─────────────────┘ └──────────────────┘ └─────────────────┘ └─────────────────┘
|
|
187
|
-
│
|
|
188
|
-
▼
|
|
189
|
-
┌─────────────────┐
|
|
190
|
-
│ Execute LLM │
|
|
191
|
-
│ + Track Cost │
|
|
192
|
-
└─────────────────┘
|
|
80
|
+
# Start proxy on custom port
|
|
81
|
+
npx a3m-router serve --port 3000
|
|
193
82
|
```
|
|
194
83
|
|
|
195
|
-
|
|
84
|
+
---
|
|
196
85
|
|
|
197
|
-
|
|
198
|
-
- ✅ **Learned Routing** - RouteLLM-style optimization
|
|
199
|
-
- ✅ **Cost Tracking** - Real-time spend monitoring
|
|
200
|
-
- ✅ **Automatic Fallback** - Retry with backup providers
|
|
201
|
-
- ✅ **Batch Processing** - Parallel execution
|
|
202
|
-
- ✅ **Response Caching** - RadixAttention-style
|
|
203
|
-
- ✅ **Circuit Breakers** - Fail-fast protection
|
|
86
|
+
## What's Included
|
|
204
87
|
|
|
205
|
-
###
|
|
206
|
-
- 🔒 **Input Validation** - Sanitize and validate inputs
|
|
207
|
-
- 🔒 **Prompt Injection Detection** - Block attacks
|
|
208
|
-
- 🔒 **PII Detection** - Protect sensitive data
|
|
209
|
-
- 🔒 **Content Filtering** - Block harmful content
|
|
210
|
-
- 🔒 **Rate Limiting** - Prevent abuse
|
|
88
|
+
### 🛤️ OpenAI-Compatible Proxy Server
|
|
211
89
|
|
|
212
|
-
|
|
90
|
+
Drop-in replacement for `api.openai.com`. Switch one URL, save 70%. No SDK changes.
|
|
213
91
|
|
|
214
|
-
|
|
215
|
-
- Groq (llama-3.3-70b, llama-3.1-8b)
|
|
216
|
-
- Cerebras (llama3.1-8b, qwen-3-235b)
|
|
217
|
-
- Mistral (small, medium, large, devstral)
|
|
218
|
-
- OpenAI (GPT-4, GPT-4o, GPT-3.5)
|
|
219
|
-
- Anthropic (Claude 3.5 Sonnet, Claude 3 Opus)
|
|
220
|
-
- Google (Gemini 2.5, Gemini 2.0)
|
|
221
|
-
- DeepSeek (deepseek-chat, deepseek-reasoner)
|
|
92
|
+
### 📊 Real-Time Dashboard
|
|
222
93
|
|
|
223
|
-
|
|
224
|
-
- CommandCode (taste-1)
|
|
225
|
-
- OpenCode (116+ models)
|
|
94
|
+
Live cost tracking, provider health, request logs — running at `http://localhost:8787/` the moment you start the server.
|
|
226
95
|
|
|
227
|
-
|
|
228
|
-
- Ollama
|
|
229
|
-
- vLLM
|
|
230
|
-
- LM Studio
|
|
96
|
+
### 🧠 Intelligent Routing
|
|
231
97
|
|
|
232
|
-
|
|
98
|
+
Query complexity analysis → cheapest capable provider. Simple questions go free. Hard questions go premium. You don't think about it.
|
|
233
99
|
|
|
234
|
-
|
|
235
|
-
| Period | Downloads | Trend |
|
|
236
|
-
|--------|-----------|-------|
|
|
237
|
-
| Daily | 320 | 📈 |
|
|
238
|
-
| Weekly | 872 | 📈 |
|
|
239
|
-
| Monthly | 872 | 📈 |
|
|
100
|
+
### 🤖 LangChain Adapter
|
|
240
101
|
|
|
241
|
-
|
|
242
|
-
|
|
102
|
+
```javascript
|
|
103
|
+
import { A3MChatModel } from 'adaptive-memory-multi-model-router/langchain';
|
|
243
104
|
|
|
244
|
-
|
|
105
|
+
const model = new A3MChatModel();
|
|
106
|
+
const response = await model.invoke("Why is the sky blue?");
|
|
107
|
+
```
|
|
245
108
|
|
|
246
|
-
###
|
|
109
|
+
### 🛡️ Guardrails
|
|
247
110
|
|
|
248
|
-
|
|
249
|
-
const { registerProvider } = require('adaptive-memory-multi-model-router');
|
|
250
|
-
|
|
251
|
-
registerProvider('my-provider', {
|
|
252
|
-
name: 'MyProvider',
|
|
253
|
-
baseUrl: 'https://api.myprovider.com',
|
|
254
|
-
models: ['my-model'],
|
|
255
|
-
apiKeyEnv: 'MY_API_KEY',
|
|
256
|
-
type: 'api'
|
|
257
|
-
});
|
|
258
|
-
```
|
|
111
|
+
Prompt injection detection, PII redaction, content filtering — built in, enabled by default.
|
|
259
112
|
|
|
260
|
-
###
|
|
113
|
+
### 🗜️ Semantic Cache
|
|
261
114
|
|
|
262
|
-
|
|
263
|
-
const { validateInput } = require('adaptive-memory-multi-model-router');
|
|
115
|
+
Cache semantically similar queries. Identical meaning = instant response, zero API cost.
|
|
264
116
|
|
|
265
|
-
|
|
266
|
-
enableInjectionDetection: true,
|
|
267
|
-
enablePIIDetection: true,
|
|
268
|
-
maxLength: 1000
|
|
269
|
-
});
|
|
117
|
+
### 📈 Cost Analytics
|
|
270
118
|
|
|
271
|
-
|
|
272
|
-
console.error('Validation failed:', result.errors);
|
|
273
|
-
}
|
|
274
|
-
```
|
|
119
|
+
Track every request. See exactly where your money goes. Export savings reports.
|
|
275
120
|
|
|
276
|
-
|
|
121
|
+
---
|
|
277
122
|
|
|
278
|
-
|
|
279
|
-
const router = createA3MRouter({
|
|
280
|
-
cost: {
|
|
281
|
-
dailyBudget: 10.00, // $10/day
|
|
282
|
-
monthlyBudget: 200.00 // $200/month
|
|
283
|
-
}
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
const summary = router.costTracker.getSummary();
|
|
287
|
-
console.log(`Remaining today: $${summary.remainingDaily}`);
|
|
288
|
-
```
|
|
123
|
+
## 39 Providers
|
|
289
124
|
|
|
290
|
-
|
|
125
|
+
| Tier | Providers |
|
|
126
|
+
|------|-----------|
|
|
127
|
+
| **Free** | CommandCode, Ollama, LM Studio, vLLM |
|
|
128
|
+
| **Fast** | Groq ($0.59), Cerebras ($0.60) |
|
|
129
|
+
| **Balanced** | Mistral ($2), DeepSeek ($1.5), Qwen ($2) |
|
|
130
|
+
| **Premium** | OpenAI ($30), Anthropic ($15) |
|
|
291
131
|
|
|
292
|
-
|
|
132
|
+
Adding a provider is one line of config. Mix and match. Failover automatically.
|
|
293
133
|
|
|
294
|
-
|
|
295
|
-
- 💡 [Suggest features](https://github.com/Das-rebel/adaptive-memory-multi-model-router/discussions)
|
|
296
|
-
- 🔧 [Submit PRs](https://github.com/Das-rebel/adaptive-memory-multi-model-router/pulls)
|
|
134
|
+
---
|
|
297
135
|
|
|
298
|
-
##
|
|
136
|
+
## Comparison
|
|
299
137
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
-
|
|
304
|
-
|
|
138
|
+
| Feature | A3M Router | Portkey | LiteLLM |
|
|
139
|
+
|---------|:----------:|:-------:|:-------:|
|
|
140
|
+
| OpenAI proxy | ✅ | ✅ | ✅ |
|
|
141
|
+
| Real-time dashboard | ✅ | ✅ | ❌ |
|
|
142
|
+
| LangChain adapter | ✅ | ✅ | ✅ |
|
|
143
|
+
| Guardrails | ✅ | ✅ | ❌ |
|
|
144
|
+
| Semantic cache | ✅ | ✅ | ❌ |
|
|
145
|
+
| Providers | 39 | 250+ | 100+ |
|
|
146
|
+
| **Price** | **Free** | **Paid tiers** | **Free** |
|
|
147
|
+
| **Setup time** | **30 seconds** | **Requires account** | **Library only** |
|
|
305
148
|
|
|
306
|
-
|
|
149
|
+
---
|
|
307
150
|
|
|
308
|
-
|
|
309
|
-
- 🚀 **#1** in LLM routing category
|
|
310
|
-
- ✅ **33 tests** passing
|
|
311
|
-
- 🎯 **156 keywords** for discoverability
|
|
312
|
-
- 🔌 **116 integrations** supported
|
|
151
|
+
## Downloads
|
|
313
152
|
|
|
314
|
-
|
|
153
|
+

|
|
315
154
|
|
|
316
|
-
|
|
155
|
+
**2,775 downloads in 3 days. 1,903 yesterday. Growing fast.**
|
|
317
156
|
|
|
318
157
|
---
|
|
319
158
|
|
|
320
|
-
|
|
159
|
+
## Links
|
|
321
160
|
|
|
322
|
-
|
|
161
|
+
- 📦 [NPM](https://www.npmjs.com/package/adaptive-memory-multi-model-router)
|
|
162
|
+
- 🐙 [GitHub](https://github.com/Das-rebel/adaptive-memory-multi-model-router)
|
|
163
|
+
- 🎮 [Playground](https://codesandbox.io/p/sandbox/github/Das-rebel/adaptive-memory-multi-model-router/tree/main/playground)
|
|
323
164
|
|
|
324
|
-
|
|
165
|
+
---
|
|
325
166
|
|
|
326
|
-
|
|
167
|
+
MIT License. No vendor lock-in. No account required. Just `npm install` and go.
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "A3M Router v2.0: Now an OpenAI-Compatible AI Gateway with 39 Providers 🚀"
|
|
3
|
+
published: true
|
|
4
|
+
description: "Drop-in OpenAI proxy, LangChain adapter, guardrails, semantic cache, cost analytics, and 39 LLM providers — all in one npm package"
|
|
5
|
+
tags: node, javascript, ai, webdev
|
|
6
|
+
canonical_url: https://github.com/Das-rebel/adaptive-memory-multi-model-router
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
We just shipped A3M Router v2.0.0 — the biggest update since launch.
|
|
10
|
+
|
|
11
|
+
**What started as a simple routing library is now a full AI Gateway.**
|
|
12
|
+
|
|
13
|
+
## What's New
|
|
14
|
+
|
|
15
|
+
### 1. OpenAI-Compatible Proxy Server
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx a3m-router serve
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
That's it. You now have an OpenAI-compatible API proxy running on `localhost:8787`.
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
# Drop-in replacement — just change the base URL
|
|
25
|
+
from openai import OpenAI
|
|
26
|
+
|
|
27
|
+
client = OpenAI(
|
|
28
|
+
base_url="http://localhost:8787/v1",
|
|
29
|
+
api_key="not-needed" # A3M Router handles provider keys
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
response = client.chat.completions.create(
|
|
33
|
+
model="auto", # Intelligent routing
|
|
34
|
+
messages=[{"role": "user", "content": "Hello"}]
|
|
35
|
+
)
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Any OpenAI SDK works without code changes.** Python, Node, LangChain, LlamaIndex — just point `base_url` to A3M Router.
|
|
39
|
+
|
|
40
|
+
### 2. Real-Time Dashboard
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
http://localhost:8787/
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Live dashboard showing:
|
|
47
|
+
- Request volume and costs
|
|
48
|
+
- Provider status (online/offline)
|
|
49
|
+
- Request log with routing decisions
|
|
50
|
+
- Cost breakdown by provider
|
|
51
|
+
|
|
52
|
+
### 3. LangChain Adapter
|
|
53
|
+
|
|
54
|
+
```javascript
|
|
55
|
+
import { A3MChatModel } from 'adaptive-memory-multi-model-router/langchain';
|
|
56
|
+
|
|
57
|
+
const model = new A3MChatModel({ modelName: 'auto' });
|
|
58
|
+
const response = await model.invoke([new HumanMessage("Hello")]);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Drop-in replacement for `ChatOpenAI`. Supports streaming, tool calling, and structured output.
|
|
62
|
+
|
|
63
|
+
### 4. Guardrails Engine
|
|
64
|
+
|
|
65
|
+
```javascript
|
|
66
|
+
import { GuardrailEngine } from 'adaptive-memory-multi-model-router';
|
|
67
|
+
|
|
68
|
+
const guardrail = new GuardrailEngine({
|
|
69
|
+
promptInjection: true,
|
|
70
|
+
piiDetection: true,
|
|
71
|
+
contentFilter: true
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const result = await guardrail.checkInput(userInput);
|
|
75
|
+
if (result.blocked) {
|
|
76
|
+
// Prompt injection or PII detected
|
|
77
|
+
console.log(result.reason);
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Built-in detection for:
|
|
82
|
+
- Prompt injection attempts
|
|
83
|
+
- PII (emails, phones, SSNs, credit cards, API keys)
|
|
84
|
+
- Harmful content
|
|
85
|
+
- Language detection for routing
|
|
86
|
+
|
|
87
|
+
### 5. Semantic Cache
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
import { SemanticCache } from 'adaptive-memory-multi-model-router';
|
|
91
|
+
|
|
92
|
+
const cache = new SemanticCache({ similarityThreshold: 0.92 });
|
|
93
|
+
|
|
94
|
+
// First query: miss, calls provider
|
|
95
|
+
const result1 = await cache.get("What is Python?");
|
|
96
|
+
|
|
97
|
+
// Semantically similar: HIT (no API call!)
|
|
98
|
+
const result2 = await cache.get("Tell me about Python");
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Catches semantically similar queries using n-gram similarity. No embedding API needed.
|
|
102
|
+
|
|
103
|
+
### 6. Cost Analytics
|
|
104
|
+
|
|
105
|
+
```javascript
|
|
106
|
+
import { CostAnalytics } from 'adaptive-memory-multi-model-router';
|
|
107
|
+
|
|
108
|
+
const analytics = new CostAnalytics();
|
|
109
|
+
analytics.record({ provider: 'groq', cost: 0.001, latency: 420 });
|
|
110
|
+
|
|
111
|
+
const savings = analytics.getSavings('openai');
|
|
112
|
+
// Total saved: $X, XX% cheaper, projected monthly savings: $Y
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### 7. 39 Providers (was 12)
|
|
116
|
+
|
|
117
|
+
New providers added:
|
|
118
|
+
- **Local**: Ollama, LM Studio, vLLM
|
|
119
|
+
- **Cheap/Fast**: DeepInfra, Together AI, Fireworks, Anyscale, Novita, SambaNova
|
|
120
|
+
- **Mid-tier**: Cohere, Perplexity, AI21
|
|
121
|
+
- **Asian**: DeepSeek, Moonshot, Qwen, Zhipu, Yi
|
|
122
|
+
- **Enterprise**: Azure OpenAI, AWS Bedrock, Google Vertex
|
|
123
|
+
|
|
124
|
+
## Quick Start
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# Install
|
|
128
|
+
npm install adaptive-memory-multi-model-router
|
|
129
|
+
|
|
130
|
+
# Start the gateway
|
|
131
|
+
npx a3m-router serve
|
|
132
|
+
|
|
133
|
+
# Or use as a library
|
|
134
|
+
node -e "const { createA3MRouter } = require('adaptive-memory-multi-model-router'); ..."
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## The Numbers
|
|
138
|
+
|
|
139
|
+
| Metric | v1.9.5 | v2.0.0 |
|
|
140
|
+
|--------|--------|--------|
|
|
141
|
+
| Providers | 12 | 39 |
|
|
142
|
+
| Exports | 13 | 17 |
|
|
143
|
+
| Proxy server | ❌ | ✅ |
|
|
144
|
+
| Dashboard | ❌ | ✅ |
|
|
145
|
+
| LangChain | ❌ | ✅ |
|
|
146
|
+
| Guardrails | Basic | Full engine |
|
|
147
|
+
| Semantic cache | ❌ | ✅ |
|
|
148
|
+
| Cost analytics | Basic | Full analytics |
|
|
149
|
+
|
|
150
|
+
## Links
|
|
151
|
+
|
|
152
|
+
- **GitHub**: https://github.com/Das-rebel/adaptive-memory-multi-model-router
|
|
153
|
+
- **NPM**: https://www.npmjs.com/package/adaptive-memory-multi-model-router
|
|
154
|
+
- **872+ weekly downloads**
|
|
155
|
+
|
|
156
|
+
MIT license. Open source. No vendor lock-in.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
*Built because I was tired of marketing claims. Sharing the data so you don't have to benchmark yourself.*
|