Select a model from cost, latency, and capability metadata: reject candidates exceeding hard budgets, choose the least expensive model that satisfies quality requirements, and return selection reasoning with estimated spend.
Full problem description visible. Upgrade to unlock the editor, test cases, and solution.
Implement route_request(task, models, budget).
- task is a dict: {"required_capability": str, "complexity": str}.
- models is a list of dicts, each with:
{"id": str, "cost": float, "latency_ms": int, "capabilities": [str], "quality": float}.
- budget is a dict: {"max_cost": float, "max_latency_ms": int}.
Filtering rules (apply in any order, but all must be enforced):
1. Reject models where cost > budget["max_cost"].
2. Reject models where latency_ms > budget["max_latency_ms"].
3. Reject models where required_capability is not in capabilities.
4. Reject models where quality < 0.7.
If no models survive filtering, return:
{"selected": None, "reason": "no suitable model found", "estimated_cost": 0, "candidates_considered": len(models)}.
Otherwise, select the surviving model with the lowest cost. Return:
{"selected": model["id"], "reason": "selected by lowest cost", "estimated_cost": model["cost"], "candidates_considered": len(models)}.
₹999/monthLimited period launch pricing.
Get the full problem statement, test cases, interactive editor, solution explanation, and visual diagram.
def route_request(task, models, budget):
"""Route a task to the cheapest model that satisfies all constraints."""Filter by budget, capability, quality; select cheapest
Already have Pro access? Sign in