adaptive-memory-multi-model-router 2.13.17 → 2.13.20

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.
Files changed (96) hide show
  1. package/.dockerignore +82 -0
  2. package/.env.example +303 -0
  3. package/.github/DISCUSSIONS_WELCOME.md +27 -0
  4. package/.github/DISCUSSION_TEMPLATE.yml +5 -0
  5. package/.github/ISSUE_TEMPLATE/bug_report.md +83 -12
  6. package/.github/ISSUE_TEMPLATE/config.yml +12 -6
  7. package/.github/ISSUE_TEMPLATE/feature_request.md +61 -10
  8. package/.github/PULL_REQUEST_TEMPLATE.md +53 -26
  9. package/.github/dependabot.yml +9 -0
  10. package/.github/workflows/codeql.yml +38 -0
  11. package/.github/workflows/npm-publish.yml +20 -0
  12. package/.github/workflows/stale.yml +56 -0
  13. package/ARCHITECTURE.md +346 -0
  14. package/AUDIT_REPORT.md +28 -0
  15. package/CHANGELOG.md +386 -22
  16. package/CONTRIBUTORS.md +20 -0
  17. package/Dockerfile +53 -0
  18. package/Dockerfile.proxy +33 -0
  19. package/PR_STATUS_REPORT.md +148 -0
  20. package/README.md +22 -0
  21. package/RUNKIT.md +83 -0
  22. package/_schema.html +61 -15
  23. package/articles/AI_AGENT_LLM_ROUTING.md +150 -0
  24. package/articles/FROM_ZERO_TO_10K.md +107 -0
  25. package/articles/LLM_BENCHMARK_DEEP_DIVE.md +153 -0
  26. package/articles/TWEETS_10K_DOWNLOADS.md +47 -0
  27. package/articles/TWEETS_BENCHMARK_FIRST.md +46 -0
  28. package/articles/TWEETS_MCP_PLAY.md +51 -0
  29. package/articles/TWEETS_SEQUENTIAL_BROKEN.md +49 -0
  30. package/articles/TWEETS_WHY_BUILD.md +54 -0
  31. package/benchmark-results.json +26 -45
  32. package/cli/a3m +840 -0
  33. package/demo/package.json +13 -0
  34. package/demo/public/index.html +762 -0
  35. package/demo/server.js +405 -0
  36. package/dist/cli.js +4 -0
  37. package/docker-compose.yml +74 -0
  38. package/docs/.nojekyll +0 -0
  39. package/docs/BENCHMARK.md +96 -22
  40. package/docs/_config.yml +49 -0
  41. package/docs/api.html +513 -0
  42. package/docs/benchmark.html +387 -0
  43. package/docs/cli-cheatsheet.md +339 -0
  44. package/docs/comparison.md +108 -0
  45. package/docs/curl-examples.md +247 -0
  46. package/docs/index.html +390 -99
  47. package/docs/openapi.yaml +1318 -0
  48. package/docs/quick-start.html +366 -0
  49. package/docs/robots.txt +1 -1
  50. package/docs/sitemap.xml +23 -5
  51. package/docs/styles.css +682 -0
  52. package/examples/README.md +61 -0
  53. package/examples/a3m-sdk.js +124 -0
  54. package/examples/basic-route.js +54 -0
  55. package/examples/chat-loop.js +202 -0
  56. package/examples/classify-then-route.js +102 -0
  57. package/examples/cost-compare.js +120 -0
  58. package/examples/ensemble.js +160 -0
  59. package/hf-space/README.md +22 -0
  60. package/hf-space/app.py +97 -0
  61. package/integrations/langchain/README.md +216 -0
  62. package/integrations/langchain/a3m_langchain.ts +1360 -0
  63. package/integrations/langchain/example.ts +287 -0
  64. package/integrations/vercel-ai-sdk/README.md +49 -0
  65. package/integrations/vercel-ai-sdk/a3m_provider.ts +78 -0
  66. package/integrations/vercel-ai-sdk/example.ts +25 -0
  67. package/llms-full.txt +43 -0
  68. package/llms.txt +9 -0
  69. package/mcp-server/README.md +188 -0
  70. package/mcp-server/package.json +29 -0
  71. package/mcp-server/src/index.ts +744 -0
  72. package/mcp-server/tsconfig.json +19 -0
  73. package/package.json +3 -3
  74. package/proxy/README.md +227 -0
  75. package/proxy/package-lock.json +831 -0
  76. package/proxy/package.json +17 -0
  77. package/proxy/rate-limit.js +145 -0
  78. package/proxy/rate-limit.test.js +311 -0
  79. package/proxy/server.js +970 -0
  80. package/scripts/banner.js +29 -0
  81. package/scripts/compare-providers.sh +230 -0
  82. package/scripts/cross_post.py +443 -0
  83. package/scripts/publish_fcc.py +106 -0
  84. package/scripts/push-to-gitee.sh +52 -0
  85. package/src/tui/dashboard.ts +13 -0
  86. package/tests/__mocks__/tokenUtils.ts +22 -0
  87. package/tests/memory/episodicMemory.test.ts +227 -0
  88. package/tests/package-lock.json +1628 -0
  89. package/tests/package.json +18 -0
  90. package/tests/routing/ensembleVoting.test.ts +236 -0
  91. package/tests/routing/providerRetry.test.ts +360 -0
  92. package/tests/routing/queryTypePresets.test.ts +206 -0
  93. package/tests/tsconfig.json +21 -0
  94. package/tests/vitest.config.ts +18 -0
  95. package/.env +0 -2
  96. package/media/a3m-tui-screenshot.png +0 -0
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "NodeNext",
5
+ "moduleResolution": "NodeNext",
6
+ "lib": ["ES2022"],
7
+ "outDir": "./dist",
8
+ "rootDir": "./src",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "declaration": true,
14
+ "sourceMap": true,
15
+ "resolveJsonModule": true
16
+ },
17
+ "include": ["src/**/*"],
18
+ "exclude": ["node_modules", "dist"]
19
+ }
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "adaptive-memory-multi-model-router",
3
- "version": "2.13.17",
3
+ "version": "2.13.20",
4
4
  "shortName": "A3M Router",
5
5
  "displayName": "A3M Router - Adaptive Memory Multi-Model Router",
6
- "description": "🔥 Fastest-growing npm LLM router 0 to 10K downloads in 14 days. Parallel multi-LLM execution with independent benchmark validation (138ms baseline, +96ms proxy overhead), 47+ providers, 99.5% routing accuracy, 62% cost savings. Open-source AI gateway with ensemble voting, semantic cache, budget enforcement. 19.5 KB, zero ML.",
6
+ "description": "\ud83d\udd25 Fastest-growing npm LLM router \u2014 0 to 10K downloads in 14 days. Parallel multi-LLM execution with independent benchmark validation (138ms baseline, +96ms proxy overhead), 47+ providers, 99.5% routing accuracy, 62% cost savings. Open-source AI gateway with ensemble voting, semantic cache, budget enforcement. 19.5 KB, zero ML.",
7
7
  "main": "dist/index.js",
8
8
  "bin": {
9
9
  "a3m-router": "dist/cli.js",
@@ -119,7 +119,7 @@
119
119
  "bugs": {
120
120
  "url": "https://github.com/Das-rebel/a3m-router/issues"
121
121
  },
122
- "homepage": "https://github.com/Das-rebel/a3m-router",
122
+ "homepage": "https://das-rebel.github.io/A3M-Router-Parallel-multi-LLM-Gateway/",
123
123
  "scripts": {
124
124
  "test": "node test.js && node test/provider-test.js",
125
125
  "test:py": "python3 -m pytest -q",
@@ -0,0 +1,227 @@
1
+ # A3M Router Proxy
2
+
3
+ OpenAI-compatible API proxy for the **A3M Router** — intelligent multi-LLM routing with 47+ providers.
4
+
5
+ Drop-in replacement for `api.openai.com`. Point any OpenAI-compatible client at this proxy to get A3M's smart routing, cost optimization, and parallel ensemble execution.
6
+
7
+ ## Quick Start
8
+
9
+ ```bash
10
+ # Install dependencies
11
+ cd proxy
12
+ npm install
13
+
14
+ # Set API keys (at least one)
15
+ export NVIDIA_API_KEY="nvapi-..."
16
+ export GROQ_API_KEY="gsk_..."
17
+ # ... or any of 40+ supported providers
18
+
19
+ # Start the proxy
20
+ node server.js
21
+ ```
22
+
23
+ The proxy starts on `http://localhost:8787`.
24
+
25
+ ## Usage
26
+
27
+ ### curl
28
+
29
+ ```bash
30
+ curl http://localhost:8787/v1/chat/completions \
31
+ -H "Content-Type: application/json" \
32
+ -d '{
33
+ "model": "a3m-auto",
34
+ "messages": [{"role": "user", "content": "What is the capital of France?"}]
35
+ }'
36
+ ```
37
+
38
+ ### OpenAI SDK (Node.js, Python, etc.)
39
+
40
+ ```javascript
41
+ import OpenAI from "openai";
42
+
43
+ const client = new OpenAI({
44
+ baseURL: "http://localhost:8787/v1", // ← just change this
45
+ apiKey: "sk-unused", // A3M uses env vars, not this key
46
+ });
47
+
48
+ const response = await client.chat.completions.create({
49
+ model: "a3m-auto",
50
+ messages: [{ role: "user", content: "Hello" }],
51
+ });
52
+
53
+ console.log(response.choices[0].message.content);
54
+ ```
55
+
56
+ ### LangChain
57
+
58
+ ```javascript
59
+ import { ChatOpenAI } from "@langchain/openai";
60
+
61
+ const model = new ChatOpenAI({
62
+ model: "a3m-auto",
63
+ configuration: {
64
+ baseURL: "http://localhost:8787/v1",
65
+ },
66
+ apiKey: "sk-unused",
67
+ });
68
+
69
+ const response = await model.invoke([
70
+ { role: "user", content: "Explain quantum computing" },
71
+ ]);
72
+ ```
73
+
74
+ ### Vercel AI SDK
75
+
76
+ ```javascript
77
+ import { openai } from "@ai-sdk/openai";
78
+
79
+ const model = openai("a3m-auto", {
80
+ baseURL: "http://localhost:8787/v1",
81
+ });
82
+
83
+ const { text } = await generateText({
84
+ model,
85
+ prompt: "What is the meaning of life?",
86
+ });
87
+ ```
88
+
89
+ ## Model Names
90
+
91
+ | Model | Strategy | Description |
92
+ |-------|----------|-------------|
93
+ | `a3m-auto` | Intelligent routing | Best model for your query (default) |
94
+ | `a3m-cheapest` | Cost optimization | Routes to cheapest available provider |
95
+ | `a3m-fastest` | Speed optimization | Routes to fastest available provider |
96
+ | `a3m-ensemble` | Parallel execution | Runs 3 providers in parallel, picks best result |
97
+ | `gpt-4`, `gpt-4o` | OpenAI alias | Maps through A3M to best available premium model |
98
+ | `gpt-3.5-turbo` | OpenAI alias | Maps through A3M to best available fast/cheap model |
99
+ | `groq/llama-3.3-70b-versatile` | Direct | Specific provider/model pair |
100
+ | `claude-3.5-sonnet` | Direct | Anthropic model (requires `ANTHROPIC_API_KEY`) |
101
+
102
+ ## Streaming
103
+
104
+ Streaming is supported via Server-Sent Events (SSE). Just set `stream: true` in your request.
105
+
106
+ ```bash
107
+ curl http://localhost:8787/v1/chat/completions \
108
+ -H "Content-Type: application/json" \
109
+ -d '{
110
+ "model": "a3m-auto",
111
+ "messages": [{"role": "user", "content": "Tell me a story"}],
112
+ "stream": true
113
+ }'
114
+ ```
115
+
116
+ ## Environment Variables
117
+
118
+ Set API keys for the providers you want to use. A3M auto-detects available providers from env vars.
119
+
120
+ | Variable | Provider |
121
+ |----------|----------|
122
+ | `NVIDIA_API_KEY` | NVIDIA NIM (free tier) |
123
+ | `GROQ_API_KEY` | Groq (fast inference) |
124
+ | `CEREBRAS_API_KEY` | Cerebras |
125
+ | `OPENAI_API_KEY` | OpenAI |
126
+ | `ANTHROPIC_API_KEY` | Anthropic |
127
+ | `GOOGLE_API_KEY` | Google Gemini |
128
+ | `MISTRAL_API_KEY` | Mistral |
129
+ | `DEEPSEEK_API_KEY` | DeepSeek |
130
+ | `TOGETHER_API_KEY` | Together AI |
131
+ | `FIREWORKS_API_KEY` | Fireworks AI |
132
+ | `OPENROUTER_API_KEY` | OpenRouter |
133
+ | `PERPLEXITY_API_KEY` | Perplexity |
134
+ | `XAI_API_KEY` | xAI (Grok) |
135
+ | `DEEPINFRA_API_KEY` | DeepInfra |
136
+ | `SAMBANOVA_API_KEY` | SambaNova |
137
+ | `ANYSCALE_API_KEY` | Anyscale |
138
+ | `REPLICATE_API_KEY` | Replicate |
139
+ | `NOVITA_API_KEY` | Novita AI |
140
+ | `COHERE_API_KEY` | Cohere |
141
+ | `AI21_API_KEY` | AI21 Labs |
142
+ | `ZHIPU_API_KEY` | Zhipu (GLM) |
143
+ | `MOONSHOT_API_KEY` | Moonshot (Kimi) |
144
+ | `DASHSCOPE_API_KEY` | Alibaba Qwen |
145
+ | `YI_API_KEY` | Yi (01.AI) |
146
+ | `MINIMAX_API_KEY` | MiniMax |
147
+
148
+ No providers configured? A3M will try local providers (Ollama on port 11434, LM Studio on port 1234, vLLM on port 8000) automatically.
149
+
150
+ ## Port Configuration
151
+
152
+ ```bash
153
+ # Via environment variable
154
+ PORT=8080 node server.js
155
+
156
+ # Or change in server.js (default: 8787)
157
+ ```
158
+
159
+ ## Provider Configuration File
160
+
161
+ For advanced configuration (custom base URLs, model lists, cost overrides):
162
+
163
+ Create `~/.config/a3m-router/providers.json`:
164
+
165
+ ```json
166
+ {
167
+ "providers": {
168
+ "local-llama": {
169
+ "baseUrl": "http://192.168.1.100:8000/v1/chat/completions",
170
+ "models": ["llama-3.1-70b"],
171
+ "apiKeyEnv": "CUSTOM_API_KEY",
172
+ "tier": "free",
173
+ "costPerK": { "input": 0, "output": 0 }
174
+ }
175
+ }
176
+ }
177
+ ```
178
+
179
+ ## Response Headers
180
+
181
+ Every response includes diagnostic headers:
182
+
183
+ | Header | Description |
184
+ |--------|-------------|
185
+ | `X-A3M-Proxy` | Always `true` |
186
+ | `X-A3M-Provider` | Provider that served the request |
187
+ | `X-A3M-Resolved` | Actual model name used |
188
+
189
+ ## Health Check
190
+
191
+ ```bash
192
+ curl http://localhost:8787/health
193
+ ```
194
+
195
+ Returns provider availability, uptime, and proxy version.
196
+
197
+ ## Architecture
198
+
199
+ ```
200
+ ┌──────────────┐ ┌───────────────────┐ ┌──────────────┐
201
+ │ Any Client │────▶│ A3M Proxy Server │────▶│ NVIDIA NIM │
202
+ │ (OpenAI SDK) │ │ localhost:8787 │ │ Groq │
203
+ │ LangChain │ │ Express + Fetch │ │ OpenAI │
204
+ │ Vercel AI │ │ A3M Router Core │ │ Anthropic │
205
+ │ curl │ │ Route Resolution │ │ 40+ more... │
206
+ └──────────────┘ └───────────────────┘ └──────────────┘
207
+
208
+ ┌─────────┴─────────┐
209
+ │ Route Strategies │
210
+ ├───────────────────┤
211
+ │ a3m-auto │
212
+ │ a3m-cheapest │
213
+ │ a3m-fastest │
214
+ │ a3m-ensemble ◀───│ Unique: parallel
215
+ │ │ multi-LLM execution
216
+ └───────────────────┘ with result merging
217
+ ```
218
+
219
+ ## Why A3M Proxy?
220
+
221
+ **Nobody does parallel multi-LLM execution with result merging.** Everyone else does sequential fallback (try A -> B -> C). A3M's parallel ensemble with intelligent routing is unmatched.
222
+
223
+ - **47+ providers** — one proxy, any LLM
224
+ - **62% cost savings** — auto-routes to cheapest adequate model
225
+ - **138ms baseline, +96ms proxy overhead** — independently benchmarked
226
+ - **99.5% routing accuracy** — validated on golden test set
227
+ - **Zero ML deps** — 19.5 KB, pure JS