adaptive-memory-multi-model-router 1.9.5 → 2.0.0
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/ISSUE_TEMPLATE/bug_report.md +50 -0
- package/.github/ISSUE_TEMPLATE/config.yml +11 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +37 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +44 -0
- package/.github/workflows/npm-stats-validation.yml +152 -0
- package/.github/workflows/pages.yml +37 -0
- package/CHANGELOG.md +122 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +110 -0
- package/LAUNCH-PAIN-DRIVEN.md +339 -0
- package/LAUNCH.md +575 -0
- package/POPULARITY_BOOSTERS.md +285 -0
- package/README.md +231 -300
- package/SECURITY.md +69 -0
- package/articles/CONTENT_STRUCTURE.md +292 -0
- package/articles/DEVTO_COST_GUIDE.md +473 -0
- package/articles/DEVTO_FINAL.md +416 -0
- package/articles/DEVTO_MULTI_PROVIDER.md +542 -0
- package/articles/HN_10X_BETTER.md +430 -0
- package/articles/HN_CHINESE_STYLE.md +308 -0
- package/articles/HN_FINAL.md +199 -0
- package/articles/HN_POSTED_VERSION.md +56 -0
- package/articles/HN_RESEARCH.md +364 -0
- package/articles/PAIN-DRIVEN-devto-v2.md +308 -0
- package/articles/PAIN-DRIVEN-devto-v3.md +268 -0
- package/articles/PAIN-DRIVEN-devto.md +242 -0
- package/articles/PAIN-DRIVEN-hackernews-v2.md +138 -0
- package/articles/PAIN-DRIVEN-hackernews-v3.md +151 -0
- package/articles/PAIN-DRIVEN-hackernews.md +131 -0
- package/articles/PAIN-DRIVEN-reddit-v2.md +301 -0
- package/articles/PAIN-DRIVEN-reddit-v3.md +236 -0
- package/articles/PAIN-DRIVEN-reddit.md +218 -0
- package/articles/PAIN-DRIVEN-twitter-v2.md +110 -0
- package/articles/PAIN-DRIVEN-twitter-v3.md +121 -0
- package/articles/PAIN-DRIVEN-twitter.md +120 -0
- package/articles/PORTKEY_VS_A3M.md +147 -0
- package/articles/REDDIT_FINAL.md +232 -0
- package/articles/TWITTER_FINAL.md +167 -0
- package/articles/WHY_10X_BETTER.md +261 -0
- package/articles/WHY_CHINESE_STYLE_BETTER.md +323 -0
- package/articles/hashnode-llm-cost-optimization.md +125 -0
- package/articles/medium-building-llm-router.md +205 -0
- package/articles/twitter-thread-cost-savings.md +98 -0
- package/articles/youtube-tutorial-script.md +262 -0
- package/assets/banner.svg +109 -0
- package/assets/logo.svg +68 -0
- package/assets/social-preview.svg +64 -0
- package/demo/demo-script.md +53 -0
- package/dist/analytics/costAnalytics.d.ts +77 -0
- package/dist/analytics/costAnalytics.d.ts.map +1 -0
- package/dist/analytics/costAnalytics.js +219 -0
- package/dist/analytics/costAnalytics.js.map +1 -0
- package/dist/cache/semanticCache.d.ts +62 -0
- package/dist/cache/semanticCache.d.ts.map +1 -0
- package/dist/cache/semanticCache.js +176 -0
- package/dist/cache/semanticCache.js.map +1 -0
- package/dist/cli.js +35 -0
- package/dist/index.d.ts +4 -723
- package/dist/index.js +11 -362
- package/dist/index.js.map +1 -1
- package/dist/integrations/langchainAdapter.d.ts +146 -0
- package/dist/integrations/langchainAdapter.d.ts.map +1 -0
- package/dist/integrations/langchainAdapter.js +731 -0
- package/dist/integrations/langchainAdapter.js.map +1 -0
- package/dist/integrations/oauth.d.ts +69 -0
- package/dist/integrations/oauth.d.ts.map +1 -0
- package/dist/integrations/oauth.js +225 -21
- package/dist/integrations/oauth.js.map +1 -0
- package/dist/memory/autoFetch.d.ts +39 -0
- package/dist/memory/autoFetch.d.ts.map +1 -0
- package/dist/memory/autoFetch.js +80 -88
- package/dist/memory/autoFetch.js.map +1 -0
- package/dist/memory/memoryTree.d.ts +76 -0
- package/dist/memory/memoryTree.d.ts.map +1 -0
- package/dist/memory/memoryTree.js +185 -130
- package/dist/memory/memoryTree.js.map +1 -0
- package/dist/memory/obsidianVault.d.ts +71 -0
- package/dist/memory/obsidianVault.d.ts.map +1 -0
- package/dist/memory/obsidianVault.js +207 -22
- package/dist/memory/obsidianVault.js.map +1 -0
- package/dist/providers/providerConfig.d.ts +49 -0
- package/dist/providers/providerConfig.d.ts.map +1 -0
- package/dist/providers/providerConfig.js +806 -401
- package/dist/providers/providerConfig.js.map +1 -0
- package/dist/security/guardrails.d.ts +76 -0
- package/dist/security/guardrails.d.ts.map +1 -0
- package/dist/security/guardrails.js +479 -0
- package/dist/security/guardrails.js.map +1 -0
- package/dist/server/dashboard.d.ts +58 -0
- package/dist/server/dashboard.d.ts.map +1 -0
- package/dist/server/dashboard.js +553 -0
- package/dist/server/dashboard.js.map +1 -0
- package/dist/server/modelMapper.d.ts +43 -0
- package/dist/server/modelMapper.d.ts.map +1 -0
- package/dist/server/modelMapper.js +154 -0
- package/dist/server/modelMapper.js.map +1 -0
- package/dist/server/proxyServer.d.ts +41 -0
- package/dist/server/proxyServer.d.ts.map +1 -0
- package/dist/server/proxyServer.js +932 -0
- package/dist/server/proxyServer.js.map +1 -0
- package/dist/skills/__tests__/skill_manager.test.d.ts +2 -0
- package/dist/skills/__tests__/skill_manager.test.d.ts.map +1 -0
- package/dist/skills/__tests__/skill_manager.test.js +268 -0
- package/dist/skills/__tests__/skill_manager.test.js.map +1 -0
- package/docs-site/index.html +347 -0
- package/package.json +53 -7
- package/playground/README.md +51 -0
- package/playground/codesandbox.json +12 -0
- package/playground/index.js +39 -0
- package/scripts/update-npm-badges.js +158 -0
- package/src/analytics/costAnalytics.ts +304 -0
- package/src/cache/semanticCache.ts +221 -0
- package/src/index.ts +6 -0
- package/src/integrations/langchainAdapter.ts +955 -0
- package/src/providers/providerConfig.ts +923 -0
- package/src/security/guardrails.ts +585 -0
- package/src/server/dashboard.ts +610 -0
- package/src/server/modelMapper.ts +182 -0
- package/src/server/proxyServer.ts +1105 -0
- package/src/types/langchain.d.ts +83 -0
- package/tsconfig.build.json +20 -0
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Building a Production-Ready LLM Router: Lessons from 872 Weekly Downloads
|
|
3
|
+
subtitle: How we created an intelligent routing system that optimizes cost vs quality for multi-provider LLM applications
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Building a Production-Ready LLM Router: Lessons from 872 Weekly Downloads
|
|
7
|
+
|
|
8
|
+
After 18 versions and 872 weekly downloads on npm, here's what we learned building `adaptive-memory-multi-model-router` - a learned LLM routing system for production applications.
|
|
9
|
+
|
|
10
|
+
## Why LLM Routing Matters
|
|
11
|
+
|
|
12
|
+
Most applications use a single LLM provider (usually OpenAI). This is expensive and suboptimal:
|
|
13
|
+
|
|
14
|
+
- **Cost**: GPT-4 costs $0.03/1K tokens. Groq costs $0.59/1M tokens (50x cheaper).
|
|
15
|
+
- **Latency**: Some providers are 10x faster for specific tasks.
|
|
16
|
+
- **Reliability**: Single provider = single point of failure.
|
|
17
|
+
- **Quality**: Different models excel at different tasks.
|
|
18
|
+
|
|
19
|
+
## The Architecture
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
Query → Feature Extraction → Router → Provider Selection → Execution
|
|
23
|
+
↓ ↓ ↓
|
|
24
|
+
Code? Math? Cost/Quality Fallback Chain
|
|
25
|
+
Translation? Tradeoff Health Checks
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 1. Feature Extraction
|
|
29
|
+
|
|
30
|
+
We analyze queries for:
|
|
31
|
+
- **Code patterns**: function, class, import, def
|
|
32
|
+
- **Math notation**: ∫, ∑, √, equations
|
|
33
|
+
- **Language**: Multilingual detection (Chinese, Japanese, etc.)
|
|
34
|
+
- **Task type**: translation, creative writing, reasoning
|
|
35
|
+
- **Complexity**: Length + pattern density
|
|
36
|
+
|
|
37
|
+
### 2. Model Profiles
|
|
38
|
+
|
|
39
|
+
Each provider model has a profile:
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
{
|
|
43
|
+
name: "groq/llama-3.3-70b",
|
|
44
|
+
provider: "groq",
|
|
45
|
+
cost_per_1k_input: 0.59,
|
|
46
|
+
cost_per_1k_output: 0.79,
|
|
47
|
+
latency_ms: 400,
|
|
48
|
+
quality_score: 0.82,
|
|
49
|
+
strengths: ["fast", "coding"],
|
|
50
|
+
context_window: 128000
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### 3. Routing Algorithm
|
|
55
|
+
|
|
56
|
+
Inspired by RouteLLM (arXiv:2404.06035):
|
|
57
|
+
|
|
58
|
+
```javascript
|
|
59
|
+
// Complexity-weighted scoring
|
|
60
|
+
if (complexity < 0.5) {
|
|
61
|
+
// Simple query → prioritize cost
|
|
62
|
+
score = quality * 0.3 + cost_efficiency * 0.7;
|
|
63
|
+
} else {
|
|
64
|
+
// Complex query → prioritize quality
|
|
65
|
+
score = quality * 0.7 + cost_efficiency * 0.3;
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Key Design Decisions
|
|
70
|
+
|
|
71
|
+
### 1. Generic Provider System
|
|
72
|
+
|
|
73
|
+
Users can add any provider without code changes:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
// ~/.config/a3m-router/providers.json
|
|
77
|
+
{
|
|
78
|
+
"providers": {
|
|
79
|
+
"my-provider": {
|
|
80
|
+
"baseUrl": "https://api.myprovider.com",
|
|
81
|
+
"apiKeyEnv": "MY_API_KEY",
|
|
82
|
+
"models": ["my-model"],
|
|
83
|
+
"type": "api"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 2. Learned vs. Rule-Based
|
|
90
|
+
|
|
91
|
+
We started with rule-based routing (if code → use provider X). It didn't scale.
|
|
92
|
+
|
|
93
|
+
Now we use learned routing:
|
|
94
|
+
- Online learning from actual performance
|
|
95
|
+
- Quality ratings from user feedback
|
|
96
|
+
- Latency updates from real measurements
|
|
97
|
+
|
|
98
|
+
### 3. Cost Tracking
|
|
99
|
+
|
|
100
|
+
Real-time spend monitoring:
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
const router = createA3MRouter();
|
|
104
|
+
const summary = router.costTracker.getSummary();
|
|
105
|
+
|
|
106
|
+
console.log(`Total: $${summary.totalSpent}`);
|
|
107
|
+
console.log(`By provider:`, summary.byProvider);
|
|
108
|
+
console.log(`Daily:`, summary.daily);
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Production Features
|
|
112
|
+
|
|
113
|
+
### Circuit Breakers
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
const router = createA3MRouter({
|
|
117
|
+
circuitBreaker: {
|
|
118
|
+
failureThreshold: 5,
|
|
119
|
+
resetTimeout: 60000
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Response Caching
|
|
125
|
+
|
|
126
|
+
RadixAttention-style prefix caching:
|
|
127
|
+
|
|
128
|
+
```javascript
|
|
129
|
+
const router = createA3MRouter({
|
|
130
|
+
cache: {
|
|
131
|
+
ttl_seconds: 3600,
|
|
132
|
+
maxSize: 1000
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Batch Processing
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
const queries = ["Q1", "Q2", "Q3"];
|
|
141
|
+
const results = routeBatch(queries, {
|
|
142
|
+
concurrency: 5,
|
|
143
|
+
same_model: true
|
|
144
|
+
});
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Results
|
|
148
|
+
|
|
149
|
+
| Metric | Value |
|
|
150
|
+
|--------|-------|
|
|
151
|
+
| Weekly Downloads | 872 |
|
|
152
|
+
| Daily Average | 320 |
|
|
153
|
+
| Test Coverage | 33 tests |
|
|
154
|
+
| Providers Supported | 12 |
|
|
155
|
+
| Keywords | 139 |
|
|
156
|
+
| Integrations | 116 |
|
|
157
|
+
|
|
158
|
+
## Usage
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
npm install adaptive-memory-multi-model-router
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
```javascript
|
|
165
|
+
const { createA3MRouter } = require('adaptive-memory-multi-model-router');
|
|
166
|
+
|
|
167
|
+
const router = createA3MRouter();
|
|
168
|
+
|
|
169
|
+
// Route to optimal provider
|
|
170
|
+
const result = await router.route("Write Python to sort an array");
|
|
171
|
+
console.log(result.primary_model); // "groq/llama-3.3-70b"
|
|
172
|
+
console.log(result.estimated_cost); // $0.0004
|
|
173
|
+
|
|
174
|
+
// Batch processing
|
|
175
|
+
const results = router.routeBatch(queries);
|
|
176
|
+
|
|
177
|
+
// Cost tracking
|
|
178
|
+
const summary = router.costTracker.getSummary();
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## CLI
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
npx a3m-router providers # List providers
|
|
185
|
+
npx a3m-router route "query" # Route query
|
|
186
|
+
npx a3m-router benchmark # Compare providers
|
|
187
|
+
npx a3m-router status # System status
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## What's Next
|
|
191
|
+
|
|
192
|
+
1. **More providers**: Adding Together AI, AI21, Cohere
|
|
193
|
+
2. **Fine-tuned routing**: Per-user routing preferences
|
|
194
|
+
3. **Streaming optimization**: Latency-optimized streaming
|
|
195
|
+
4. **Multi-modal**: Image, audio routing
|
|
196
|
+
|
|
197
|
+
## Links
|
|
198
|
+
|
|
199
|
+
- NPM: https://www.npmjs.com/package/adaptive-memory-multi-model-router
|
|
200
|
+
- GitHub: https://github.com/Das-rebel/adaptive-memory-multi-model-router
|
|
201
|
+
- Weekly Downloads: 872+
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
*Have you built LLM routing systems? What approaches worked for you?*
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# Twitter Thread: How We Cut LLM API Costs by 70% with Smart Routing 🧵
|
|
2
|
+
|
|
3
|
+
## Tweet 1/10 - Hook
|
|
4
|
+
Our OpenAI bill hit $2,400 in one month. We built an intelligent router that cut costs by 70% while maintaining quality.
|
|
5
|
+
|
|
6
|
+
Here's how A3M Router works 🧵👇
|
|
7
|
+
|
|
8
|
+
## Tweet 2/10 - The Problem
|
|
9
|
+
Most apps use GPT-4 for EVERYTHING:
|
|
10
|
+
• Simple Q&A → GPT-4 ($0.03/query)
|
|
11
|
+
• Code gen → GPT-4 ($0.05/query)
|
|
12
|
+
• Summarization → GPT-4 ($0.02/query)
|
|
13
|
+
|
|
14
|
+
That's like using a Ferrari for grocery runs 🏎️🛒
|
|
15
|
+
|
|
16
|
+
## Tweet 3/10 - The Insight
|
|
17
|
+
Different queries need different models:
|
|
18
|
+
• "What is 2+2?" → ANY model works
|
|
19
|
+
• "Write Python" → Code-capable model
|
|
20
|
+
• "Explain quantum" → High-quality model
|
|
21
|
+
|
|
22
|
+
Why pay GPT-4 prices for simple queries?
|
|
23
|
+
|
|
24
|
+
## Tweet 4/10 - The Solution
|
|
25
|
+
A3M Router learns your usage patterns:
|
|
26
|
+
• Analyzes query characteristics
|
|
27
|
+
• Matches to optimal provider
|
|
28
|
+
• Tracks costs in real-time
|
|
29
|
+
• Falls back if provider fails
|
|
30
|
+
|
|
31
|
+
All automatic. Zero config needed.
|
|
32
|
+
|
|
33
|
+
## Tweet 5/10 - Real Numbers
|
|
34
|
+
Before: $2,400/month (all GPT-4)
|
|
35
|
+
After: $720/month (smart routing)
|
|
36
|
+
|
|
37
|
+
Savings: 70% 🎉
|
|
38
|
+
Speed: 2x faster (uses Groq for speed)
|
|
39
|
+
Quality: 94% (vs 100% GPT-4)
|
|
40
|
+
|
|
41
|
+
Trade-off: 6% quality for 70% savings
|
|
42
|
+
|
|
43
|
+
## Tweet 6/10 - How It Works
|
|
44
|
+
```javascript
|
|
45
|
+
const { routeQuery } = require('adaptive-memory-multi-model-router');
|
|
46
|
+
|
|
47
|
+
// Simple query → cheapest provider (FREE)
|
|
48
|
+
routeQuery("What is 2+2?");
|
|
49
|
+
// → commandcode/taste-1 ($0.00)
|
|
50
|
+
|
|
51
|
+
// Code query → fast provider
|
|
52
|
+
routeQuery("Write Python to reverse a string");
|
|
53
|
+
// → groq/llama-3.3-70b ($0.0004)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Tweet 7/10 - Supported Providers
|
|
57
|
+
• FREE: CommandCode, OpenCode
|
|
58
|
+
• FAST: Groq ($0.59/1M tokens)
|
|
59
|
+
• QUALITY: Mistral, OpenAI, Anthropic
|
|
60
|
+
• LOCAL: Ollama (free!)
|
|
61
|
+
|
|
62
|
+
12 providers, automatic selection
|
|
63
|
+
|
|
64
|
+
## Tweet 8/10 - Installation
|
|
65
|
+
One line to install:
|
|
66
|
+
```bash
|
|
67
|
+
npm install adaptive-memory-multi-model-router
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
One line to use:
|
|
71
|
+
```bash
|
|
72
|
+
npx a3m-router route "Your query"
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
That's it. No config needed.
|
|
76
|
+
|
|
77
|
+
## Tweet 9/10 - Results
|
|
78
|
+
📊 872+ weekly downloads
|
|
79
|
+
🧪 33 tests passing
|
|
80
|
+
🔌 116 integrations
|
|
81
|
+
🏷️ 156 keywords
|
|
82
|
+
|
|
83
|
+
Growing fast because it WORKS
|
|
84
|
+
|
|
85
|
+
## Tweet 10/10 - CTA
|
|
86
|
+
Try it today:
|
|
87
|
+
```bash
|
|
88
|
+
npm install adaptive-memory-multi-model-router
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
GitHub: github.com/Das-rebel/adaptive-memory-multi-model-router
|
|
92
|
+
NPM: npmjs.com/package/adaptive-memory-multi-model-router
|
|
93
|
+
|
|
94
|
+
Questions? Drop them below! 👇
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
#LLM #AI #OpenAI #CostOptimization #JavaScript #NodeJS #MachineLearning #DeveloperTools
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
# YouTube Tutorial Script: A3M Router - Smart LLM Routing
|
|
2
|
+
|
|
3
|
+
## Video Title Options
|
|
4
|
+
1. "Cut Your OpenAI Bill by 70% with Intelligent LLM Routing"
|
|
5
|
+
2. "A3M Router: The Smart Way to Use Multiple LLM Providers"
|
|
6
|
+
3. "Stop Overpaying for LLMs - Automatic Cost Optimization"
|
|
7
|
+
4. "Build a Learned LLM Router in 10 Minutes"
|
|
8
|
+
|
|
9
|
+
## Video Info
|
|
10
|
+
- **Target Length**: 10-12 minutes
|
|
11
|
+
- **Target Audience**: Node.js developers using LLMs
|
|
12
|
+
- **Difficulty**: Beginner to Intermediate
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Intro (0:00 - 1:00)
|
|
17
|
+
|
|
18
|
+
**[Screen: Terminal with high OpenAI bill]**
|
|
19
|
+
|
|
20
|
+
"If you're using OpenAI for everything, you're probably overpaying. In this video, I'll show you how we cut our LLM API costs by 70% using intelligent routing."
|
|
21
|
+
|
|
22
|
+
**[Screen: A3M Router logo/banner]**
|
|
23
|
+
|
|
24
|
+
"This is A3M Router - an adaptive multi-model router that automatically sends your queries to the cheapest capable provider. Let's dive in."
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## The Problem (1:00 - 2:30)
|
|
29
|
+
|
|
30
|
+
**[Screen: Code showing GPT-4 usage]**
|
|
31
|
+
|
|
32
|
+
"Here's what most developers do. They use GPT-4 for EVERYTHING."
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
// Bad: Using GPT-4 for everything
|
|
36
|
+
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
|
37
|
+
|
|
38
|
+
// Simple question
|
|
39
|
+
await openai.chat.completions.create({
|
|
40
|
+
model: "gpt-4",
|
|
41
|
+
messages: [{ role: "user", content: "What is 2+2?" }]
|
|
42
|
+
});
|
|
43
|
+
// Cost: $0.03
|
|
44
|
+
|
|
45
|
+
// Code generation
|
|
46
|
+
await openai.chat.completions.create({
|
|
47
|
+
model: "gpt-4",
|
|
48
|
+
messages: [{ role: "user", content: "Write Python to sort an array" }]
|
|
49
|
+
});
|
|
50
|
+
// Cost: $0.05
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**[Screen: Calculator showing monthly cost]**
|
|
54
|
+
|
|
55
|
+
"If you process 1,000 queries per day, that's $30-50 per day. $900-1,500 per month. Just for simple queries that any model could handle."
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## The Solution (2:30 - 4:00)
|
|
60
|
+
|
|
61
|
+
**[Screen: A3M Router architecture diagram]**
|
|
62
|
+
|
|
63
|
+
"A3M Router solves this with learned routing. It analyzes your query and picks the optimal provider."
|
|
64
|
+
|
|
65
|
+
"Here's the magic:"
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
// Good: Using A3M Router
|
|
69
|
+
const { createA3MRouter } = require('adaptive-memory-multi-model-router');
|
|
70
|
+
|
|
71
|
+
const router = createA3MRouter();
|
|
72
|
+
|
|
73
|
+
// Simple question → cheapest provider (FREE)
|
|
74
|
+
const result1 = await router.route("What is 2+2?");
|
|
75
|
+
console.log(result1.primary_model); // "commandcode/taste-1"
|
|
76
|
+
console.log(result1.estimated_cost); // $0.00
|
|
77
|
+
|
|
78
|
+
// Code generation → fast provider
|
|
79
|
+
const result2 = await router.route("Write Python to sort an array");
|
|
80
|
+
console.log(result2.primary_model); // "groq/llama-3.3-70b"
|
|
81
|
+
console.log(result2.estimated_cost); // $0.0004
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**[Screen: Side-by-side cost comparison]**
|
|
85
|
+
|
|
86
|
+
"See the difference? Simple queries go to free providers. Code queries go to fast, code-capable models. You only pay for what you need."
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Installation & Setup (4:00 - 5:30)
|
|
91
|
+
|
|
92
|
+
**[Screen: Terminal recording]**
|
|
93
|
+
|
|
94
|
+
"Let's install it and see it in action."
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
# Install
|
|
98
|
+
npm install adaptive-memory-multi-model-router
|
|
99
|
+
|
|
100
|
+
# Check providers
|
|
101
|
+
npx a3m-router providers
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**[Screen: Provider table output]**
|
|
105
|
+
|
|
106
|
+
"Look at that - 9 providers configured out of the box. Groq, Cerebras, Mistral, and free CLI providers like CommandCode and OpenCode."
|
|
107
|
+
|
|
108
|
+
"Now let's route a query:"
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
npx a3m-router route "Write Python to reverse a string"
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**[Screen: Routing result]**
|
|
115
|
+
|
|
116
|
+
"Boom! It automatically selected Groq's Llama model because it's fast and good at code. Estimated cost: $0.0004. That's 75x cheaper than GPT-4."
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## How Routing Works (5:30 - 7:00)
|
|
121
|
+
|
|
122
|
+
**[Screen: Routing algorithm visualization]**
|
|
123
|
+
|
|
124
|
+
"Here's how the routing actually works:"
|
|
125
|
+
|
|
126
|
+
"Step 1: Feature Extraction"
|
|
127
|
+
- Detects code patterns (function, class, import)
|
|
128
|
+
- Detects math notation
|
|
129
|
+
- Detects language/translation needs
|
|
130
|
+
- Estimates complexity
|
|
131
|
+
|
|
132
|
+
"Step 2: Model Profiles"
|
|
133
|
+
- Each provider has cost, latency, quality scores
|
|
134
|
+
- Groq: fast, cheap, good at code
|
|
135
|
+
- Mistral: high quality, moderate cost
|
|
136
|
+
- CommandCode: free, good for simple queries
|
|
137
|
+
|
|
138
|
+
"Step 3: Smart Selection"
|
|
139
|
+
- Simple queries → prioritize cost
|
|
140
|
+
- Complex queries → prioritize quality
|
|
141
|
+
- Automatic fallback if provider fails
|
|
142
|
+
|
|
143
|
+
**[Screen: Code showing routing result]**
|
|
144
|
+
|
|
145
|
+
```javascript
|
|
146
|
+
const result = await router.route("Your query");
|
|
147
|
+
|
|
148
|
+
console.log(result);
|
|
149
|
+
// {
|
|
150
|
+
// primary_model: "groq/llama-3.3-70b",
|
|
151
|
+
// fallback_models: ["mistral/medium", "cerebras/llama"],
|
|
152
|
+
// estimated_cost: 0.0004,
|
|
153
|
+
// confidence: 0.85,
|
|
154
|
+
// reasoning: "Selected Groq for code detected"
|
|
155
|
+
// }
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
## Real Results (7:00 - 8:30)
|
|
161
|
+
|
|
162
|
+
**[Screen: Benchmark table]**
|
|
163
|
+
|
|
164
|
+
"Let's run the benchmark to see real performance:"
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
npx a3m-router benchmark
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
**[Screen: Benchmark output]**
|
|
171
|
+
|
|
172
|
+
"Look at these results:"
|
|
173
|
+
|
|
174
|
+
| Provider | Latency | Cost/1K | Quality |
|
|
175
|
+
|----------|---------|---------|---------|
|
|
176
|
+
| Groq | 400ms | $0.59 | 82% |
|
|
177
|
+
| Cerebras | 350ms | $0.60 | 82% |
|
|
178
|
+
| Mistral | 800ms | $0.20 | 90% |
|
|
179
|
+
| CommandCode | 5s | FREE | 75% |
|
|
180
|
+
|
|
181
|
+
"For simple queries, CommandCode is FREE. For code, Groq is 5x faster than OpenAI. For quality, Mistral beats GPT-3.5 at half the price."
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## Advanced Features (8:30 - 9:30)
|
|
186
|
+
|
|
187
|
+
**[Screen: Code examples]**
|
|
188
|
+
|
|
189
|
+
"A3M Router has more tricks up its sleeve:"
|
|
190
|
+
|
|
191
|
+
"Batch Processing:"
|
|
192
|
+
```javascript
|
|
193
|
+
const queries = ["Q1", "Q2", "Q3"];
|
|
194
|
+
const results = routeBatch(queries, { same_model: true });
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
"Cost Tracking:"
|
|
198
|
+
```javascript
|
|
199
|
+
const router = createA3MRouter();
|
|
200
|
+
const summary = router.costTracker.getSummary();
|
|
201
|
+
console.log(`Total spent: $${summary.totalSpent}`);
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
"Custom Providers:"
|
|
205
|
+
```javascript
|
|
206
|
+
registerProvider('my-provider', {
|
|
207
|
+
baseUrl: 'https://api.myprovider.com',
|
|
208
|
+
models: ['my-model'],
|
|
209
|
+
type: 'api'
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
---
|
|
214
|
+
|
|
215
|
+
## Conclusion (9:30 - 10:30)
|
|
216
|
+
|
|
217
|
+
**[Screen: Summary slide]**
|
|
218
|
+
|
|
219
|
+
"To summarize:"
|
|
220
|
+
|
|
221
|
+
"✅ Install: npm install adaptive-memory-multi-model-router"
|
|
222
|
+
"✅ Route: npx a3m-router route 'Your query'"
|
|
223
|
+
"✅ Save: 50-80% on API costs"
|
|
224
|
+
"✅ Get: Automatic fallback, cost tracking, batch processing"
|
|
225
|
+
|
|
226
|
+
**[Screen: GitHub and NPM links]**
|
|
227
|
+
|
|
228
|
+
"Links in the description:
|
|
229
|
+
- GitHub: github.com/Das-rebel/adaptive-memory-multi-model-router
|
|
230
|
+
- NPM: npmjs.com/package/adaptive-memory-multi-model-router
|
|
231
|
+
- Docs: Full documentation on GitHub"
|
|
232
|
+
|
|
233
|
+
**[Screen: Subscribe button]**
|
|
234
|
+
|
|
235
|
+
"If this helped you save money on LLM APIs, hit like and subscribe. Questions? Drop them in the comments. Thanks for watching!"
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Video Assets Needed
|
|
240
|
+
|
|
241
|
+
1. **Thumbnail**: Split screen - "$2,400" vs "$720" with A3M Router logo
|
|
242
|
+
2. **Intro Animation**: 5-second logo animation
|
|
243
|
+
3. **Terminal Recording**: Actual CLI usage
|
|
244
|
+
4. **Diagram**: Routing architecture (can use ASCII art)
|
|
245
|
+
5. **Benchmark Table**: Animated comparison
|
|
246
|
+
6. **Outro Screen**: Links and subscribe button
|
|
247
|
+
|
|
248
|
+
## B-Roll Footage
|
|
249
|
+
|
|
250
|
+
- Terminal typing (can use asciinema)
|
|
251
|
+
- Code scrolling
|
|
252
|
+
- Provider logos (Groq, Mistral, etc.)
|
|
253
|
+
- Money/cost graphics
|
|
254
|
+
- Speedometer for latency
|
|
255
|
+
|
|
256
|
+
## Call to Action
|
|
257
|
+
|
|
258
|
+
- Like the video
|
|
259
|
+
- Subscribe for more
|
|
260
|
+
- Comment with questions
|
|
261
|
+
- Star on GitHub
|
|
262
|
+
- Try the package
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 400" width="1200" height="400">
|
|
2
|
+
<defs>
|
|
3
|
+
<linearGradient id="bgGradient" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
4
|
+
<stop offset="0%" style="stop-color:#0f172a;stop-opacity:1" />
|
|
5
|
+
<stop offset="50%" style="stop-color:#1e1b4b;stop-opacity:1" />
|
|
6
|
+
<stop offset="100%" style="stop-color:#312e81;stop-opacity:1" />
|
|
7
|
+
</linearGradient>
|
|
8
|
+
<linearGradient id="accentGradient" x1="0%" y1="0%" x2="100%" y2="0%">
|
|
9
|
+
<stop offset="0%" style="stop-color:#6366f1;stop-opacity:1" />
|
|
10
|
+
<stop offset="50%" style="stop-color:#8b5cf6;stop-opacity:1" />
|
|
11
|
+
<stop offset="100%" style="stop-color:#06b6d4;stop-opacity:1" />
|
|
12
|
+
</linearGradient>
|
|
13
|
+
<filter id="glowBanner">
|
|
14
|
+
<feGaussianBlur stdDeviation="4" result="coloredBlur"/>
|
|
15
|
+
<feMerge>
|
|
16
|
+
<feMergeNode in="coloredBlur"/>
|
|
17
|
+
<feMergeNode in="SourceGraphic"/>
|
|
18
|
+
</feMerge>
|
|
19
|
+
</filter>
|
|
20
|
+
<pattern id="grid" width="40" height="40" patternUnits="userSpaceOnUse">
|
|
21
|
+
<path d="M 40 0 L 0 0 0 40" fill="none" stroke="rgba(255,255,255,0.03)" stroke-width="1"/>
|
|
22
|
+
</pattern>
|
|
23
|
+
</defs>
|
|
24
|
+
|
|
25
|
+
<!-- Background -->
|
|
26
|
+
<rect width="1200" height="400" fill="url(#bgGradient)"/>
|
|
27
|
+
<rect width="1200" height="400" fill="url(#grid)"/>
|
|
28
|
+
|
|
29
|
+
<!-- Animated Particles -->
|
|
30
|
+
<g opacity="0.3">
|
|
31
|
+
<circle cx="100" cy="100" r="2" fill="#6366f1">
|
|
32
|
+
<animate attributeName="cy" values="100;120;100" dur="4s" repeatCount="indefinite"/>
|
|
33
|
+
<animate attributeName="opacity" values="0.3;0.6;0.3" dur="4s" repeatCount="indefinite"/>
|
|
34
|
+
</circle>
|
|
35
|
+
<circle cx="300" cy="300" r="3" fill="#8b5cf6">
|
|
36
|
+
<animate attributeName="cy" values="300;280;300" dur="5s" repeatCount="indefinite"/>
|
|
37
|
+
<animate attributeName="opacity" values="0.3;0.7;0.3" dur="5s" repeatCount="indefinite"/>
|
|
38
|
+
</circle>
|
|
39
|
+
<circle cx="900" cy="150" r="2" fill="#06b6d4">
|
|
40
|
+
<animate attributeName="cy" values="150;170;150" dur="3s" repeatCount="indefinite"/>
|
|
41
|
+
<animate attributeName="opacity" values="0.3;0.5;0.3" dur="3s" repeatCount="indefinite"/>
|
|
42
|
+
</circle>
|
|
43
|
+
<circle cx="1100" cy="350" r="3" fill="#10b981">
|
|
44
|
+
<animate attributeName="cy" values="350;330;350" dur="6s" repeatCount="indefinite"/>
|
|
45
|
+
<animate attributeName="opacity" values="0.3;0.6;0.3" dur="6s" repeatCount="indefinite"/>
|
|
46
|
+
</circle>
|
|
47
|
+
</g>
|
|
48
|
+
|
|
49
|
+
<!-- Main Logo Icon -->
|
|
50
|
+
<g transform="translate(150, 200)">
|
|
51
|
+
<circle cx="0" cy="0" r="60" fill="none" stroke="url(#accentGradient)" stroke-width="2" opacity="0.3"/>
|
|
52
|
+
<circle cx="0" cy="0" r="50" fill="none" stroke="url(#accentGradient)" stroke-width="1" opacity="0.2" stroke-dasharray="5 5">
|
|
53
|
+
<animateTransform attributeName="transform" type="rotate" from="0 0 0" to="360 0 0" dur="20s" repeatCount="indefinite"/>
|
|
54
|
+
</circle>
|
|
55
|
+
<circle cx="0" cy="0" r="20" fill="url(#accentGradient)" filter="url(#glowBanner)"/>
|
|
56
|
+
<circle cx="0" cy="-35" r="8" fill="#6366f1" opacity="0.9">
|
|
57
|
+
<animateTransform attributeName="transform" type="rotate" from="0 0 0" to="360 0 0" dur="8s" repeatCount="indefinite"/>
|
|
58
|
+
</circle>
|
|
59
|
+
<circle cx="30" cy="18" r="6" fill="#10b981" opacity="0.9">
|
|
60
|
+
<animateTransform attributeName="transform" type="rotate" from="120 0 0" to="480 0 0" dur="10s" repeatCount="indefinite"/>
|
|
61
|
+
</circle>
|
|
62
|
+
<circle cx="-30" cy="18" r="6" fill="#f59e0b" opacity="0.9">
|
|
63
|
+
<animateTransform attributeName="transform" type="rotate" from="240 0 0" to="600 0 0" dur="12s" repeatCount="indefinite"/>
|
|
64
|
+
</circle>
|
|
65
|
+
<text x="0" y="8" font-family="system-ui, -apple-system, sans-serif" font-size="24" font-weight="bold" fill="white" text-anchor="middle">A3M</text>
|
|
66
|
+
</g>
|
|
67
|
+
|
|
68
|
+
<!-- Title -->
|
|
69
|
+
<text x="600" y="160" font-family="system-ui, -apple-system, sans-serif" font-size="72" font-weight="bold" fill="white" text-anchor="middle" filter="url(#glowBanner)">A3M Router</text>
|
|
70
|
+
|
|
71
|
+
<!-- Subtitle -->
|
|
72
|
+
<text x="600" y="210" font-family="system-ui, -apple-system, sans-serif" font-size="28" fill="url(#accentGradient)" text-anchor="middle">Adaptive Memory Multi-Model Router</text>
|
|
73
|
+
|
|
74
|
+
<!-- Tagline -->
|
|
75
|
+
<text x="600" y="250" font-family="system-ui, -apple-system, sans-serif" font-size="18" fill="#94a3b8" text-anchor="middle">Route LLM queries to optimal providers • Save 50-80% on API costs</text>
|
|
76
|
+
|
|
77
|
+
<!-- Stats Bar -->
|
|
78
|
+
<g transform="translate(600, 320)">
|
|
79
|
+
<rect x="-350" y="0" width="700" height="50" rx="25" fill="rgba(255,255,255,0.05)" stroke="rgba(255,255,255,0.1)" stroke-width="1"/>
|
|
80
|
+
|
|
81
|
+
<!-- Stat 1 -->
|
|
82
|
+
<text x="-280" y="32" font-family="system-ui, -apple-system, sans-serif" font-size="14" font-weight="bold" fill="#6366f1" text-anchor="middle">872+</text>
|
|
83
|
+
<text x="-280" y="48" font-family="system-ui, -apple-system, sans-serif" font-size="10" fill="#64748b" text-anchor="middle">Weekly Downloads</text>
|
|
84
|
+
|
|
85
|
+
<!-- Divider -->
|
|
86
|
+
<line x1="-200" y1="10" x2="-200" y2="40" stroke="rgba(255,255,255,0.1)" stroke-width="1"/>
|
|
87
|
+
|
|
88
|
+
<!-- Stat 2 -->
|
|
89
|
+
<text x="-100" y="32" font-family="system-ui, -apple-system, sans-serif" font-size="14" font-weight="bold" fill="#10b981" text-anchor="middle">12</text>
|
|
90
|
+
<text x="-100" y="48" font-family="system-ui, -apple-system, sans-serif" font-size="10" fill="#64748b" text-anchor="middle">LLM Providers</text>
|
|
91
|
+
|
|
92
|
+
<!-- Divider -->
|
|
93
|
+
<line x1="0" y1="10" x2="0" y2="40" stroke="rgba(255,255,255,0.1)" stroke-width="1"/>
|
|
94
|
+
|
|
95
|
+
<!-- Stat 3 -->
|
|
96
|
+
<text x="100" y="32" font-family="system-ui, -apple-system, sans-serif" font-size="14" font-weight="bold" fill="#f59e0b" text-anchor="middle">116</text>
|
|
97
|
+
<text x="100" y="48" font-family="system-ui, -apple-system, sans-serif" font-size="10" fill="#64748b" text-anchor="middle">Integrations</text>
|
|
98
|
+
|
|
99
|
+
<!-- Divider -->
|
|
100
|
+
<line x1="200" y1="10" x2="200" y2="40" stroke="rgba(255,255,255,0.1)" stroke-width="1"/>
|
|
101
|
+
|
|
102
|
+
<!-- Stat 4 -->
|
|
103
|
+
<text x="280" y="32" font-family="system-ui, -apple-system, sans-serif" font-size="14" font-weight="bold" fill="#8b5cf6" text-anchor="middle">33</text>
|
|
104
|
+
<text x="280" y="48" font-family="system-ui, -apple-system, sans-serif" font-size="10" fill="#64748b" text-anchor="middle">Tests Passing</text>
|
|
105
|
+
</g>
|
|
106
|
+
|
|
107
|
+
<!-- Bottom Gradient Line -->
|
|
108
|
+
<rect x="0" y="395" width="1200" height="5" fill="url(#accentGradient)"/>
|
|
109
|
+
</svg>
|