Capstone — Multi-Model Router by File Type
Build a model router — route prompts to models by file type and cost.
What You Will Learn
- Build a model router.
- Route by file type.
- Cost-aware selection.
- Fallback on failure.
- Measure cost savings.
Why This Matters
Different file types benefit from different models. A router optimizes cost and quality simultaneously.
Concept Explained
Router: input file type → pick model. TypeScript → GPT-5 (strong type awareness). Python → Claude (good idioms). Markdown → GPT-5 mini (cheap). Etc.
How It Works
Build router that takes file type (or detects from extension), picks model based on config, calls Copilot. Track cost savings.
Step-by-Step Tutorial
1. Define routing rules
Per file type: TS→GPT-5, Py→Claude, MD→mini, etc.2. Build router
Function: file_type → model.3. Add fallback
If chosen model fails, fallback to next.4. Track cost
Compare to single-model baseline.5. Adjust based on data.
Refine routing rules.Real-World Example
A team built a router: TS→GPT-5, Py→Claude, MD→mini. Cost dropped 35% (cheap model for docs), quality maintained (right model per type). Adopted org-wide.
Example Prompts / Commands / Code
"""# router-config.json
{
"routing_rules": {
".ts": "gpt-5",
".tsx": "gpt-5",
".py": "claude",
".go": "claude",
".md": "gpt-5-mini",
".json": "gpt-5-mini",
".yml": "gpt-5-mini",
"default": "gpt-5"
},
"fallback_chain": {
"gpt-5": ["claude", "gpt-5-mini"],
"claude": ["gpt-5", "gpt-5-mini"],
"gpt-5-mini": ["gpt-5", "claude"]
}
}
"""
"""import os
import json
class ModelRouter:
def __init__(self, config_path='router-config.json'):
with open(config_path) as f:
self.config = json.load(f)
def pick_model(self, file_path: str) -> str:
ext = os.path.splitext(file_path)[1]
return self.config['routing_rules'].get(ext, self.config['routing_rules']['default'])
def route_with_fallback(self, file_path: str, prompt: str) -> str:
model = self.pick_model(file_path)
for m in [model] + self.config['fallback_chain'].get(model, []):
try:
return copilot.run(prompt, model=m)
except:
continue
raise RuntimeError('All models failed')
# Usage:
router = ModelRouter()
result = router.route_with_fallback('src/auth.ts', 'refactor this function')
"""
Common Mistakes
- Routing too fine-grained — complexity without benefit.
- No fallback — single model failure breaks system.
- Not tracking cost savings — can't justify router.
- Not adjusting based on data — routing stays static.
Best Practices
- Route by file type (5–10 categories).
- Build fallback chain.
- Track cost savings vs single-model baseline.
- Adjust routing based on data.
- Start simple; add complexity as justified.
Troubleshooting
| Problem | How to Fix |
|---|---|
| Router picks wrong model | Refine routing rules based on data. |
| All models fail | Graceful degradation. |
Practical Exercise
Your Turn
Build a model router with 5 file types. Track cost vs single-model baseline for a week.
Professional Challenge
Deploy router in production. Track cost savings and quality over a quarter. Document ROI.
Key Takeaways
- Router: file type → model.
- 5–10 categories is enough.
- Build fallback chain.
- Track cost savings vs baseline.
- Adjust routing based on data.
Frequently Asked Questions
Build or use auto-model?
Cost savings typical?
Further Reading
Official References
SEO Metadata
SEO title: Capstone — Multi-Model Router by File Type
Meta description: Build a model router — route prompts to models by file type and cost.
Primary keyword: capstone
Secondary keywords: capstone — multi-model router by file type
Search intent: Informational
URL slug: /capstone-multi-model-router-file-type-cost
Categories: AI Tools, GitHub Copilot
Tags: GitHub Copilot, Professional, Capstone, Multi-Model, Router, Cost, IMCSEIAN, Tutorial, IMCSEIAN
Featured image concept: IMCSEIAN lesson card for Capstone — Multi-Model Router by File Type
Comments
Comments
Post a Comment