Repository navigation
Expand file tree
/
Copy pathtest_local.py
More file actions
167 lines (136 loc) · 5.33 KB
/
Copy pathtest_local.py
File metadata and controls
167 lines (136 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/env python3
"""
Standalone test script for local development without Docker.
Run router and test routing decisions locally.
"""
import sys
import os
# Add router to path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'router'))
from engine import RoutingEngine
def test_routing():
"""Test routing engine with various scenarios."""
print("="*80)
print("MODEL ROUTER TEST - LOCAL MODE")
print("="*80)
print()
# Initialize engine
router = RoutingEngine('router/models.yaml')
print(f"Loaded {len(router.models)} models:")
for name in router.models.keys():
print(f" - {name}")
print()
# Test cases
test_cases = [
{
'name': 'Simple classification (optimize cost)',
'prompt': 'Classify this incident: User forgot password',
'constraints': {
'max_cost_per_1m_tokens': 0.50,
'max_latency_ms': 2000,
'min_accuracy_score': 0.80
},
'optimize_for': 'cost'
},
{
'name': 'Complex analysis (optimize accuracy)',
'prompt': 'Analyze root cause of database connection pool exhaustion with cascading failures',
'constraints': {
'max_cost_per_1m_tokens': 5.00,
'max_latency_ms': 5000,
'min_accuracy_score': 0.90
},
'optimize_for': 'accuracy'
},
{
'name': 'Code generation (optimize speed)',
'prompt': 'Write a Python function to parse CSV files',
'constraints': {
'max_cost_per_1m_tokens': 3.00,
'max_latency_ms': 2000,
'min_accuracy_score': 0.85
},
'optimize_for': 'speed'
},
{
'name': 'Strict budget (may fallback)',
'prompt': 'Complex multi-system architecture analysis',
'constraints': {
'max_cost_per_1m_tokens': 0.10, # Impossibly low
'max_latency_ms': 500,
'min_accuracy_score': 0.95
},
'optimize_for': 'cost'
}
]
for i, test in enumerate(test_cases, 1):
print("-"*80)
print(f"TEST {i}: {test['name']}")
print("-"*80)
print(f"Prompt: {test['prompt'][:60]}...")
print(f"Constraints: {test['constraints']}")
print(f"Optimize for: {test['optimize_for']}")
print()
result = router.route(
prompt=test['prompt'],
constraints=test['constraints'],
optimize_for=test['optimize_for']
)
print(f"✓ Selected: {result['model']}")
print(f" Provider: {result['provider']}")
print(f" Cost: ${result['reasoning']['cost_per_1m']}/1M tokens")
print(f" Latency: {result['reasoning']['estimated_latency_ms']}ms")
print(f" Accuracy: {result['reasoning']['accuracy_score']:.2f}")
print(f" Task type: {result['reasoning']['task_type']}")
if result.get('warning'):
print(f" ⚠️ Warning: {result['warning']}")
if result.get('alternatives'):
print(f" Alternatives: {len(result['alternatives'])} other models available")
print()
print("="*80)
print("COST COMPARISON")
print("="*80)
incidents = [
"Password reset request",
"Application slow performance",
"Database connection errors - production down",
]
total_optimized = 0
total_baseline = 0
for incident in incidents:
result = router.route(
prompt=incident,
constraints={
'max_cost_per_1m_tokens': 1.00,
'max_latency_ms': 3000,
'min_accuracy_score': 0.80
},
optimize_for='cost'
)
optimized = result['reasoning']['cost_per_1m']
baseline = 3.00 # Always use expensive model
total_optimized += optimized
total_baseline += baseline
print(f"Incident: {incident}")
print(f" Optimized: ${optimized}/1M ({result['model']})")
print(f" Baseline: ${baseline}/1M (always claude-sonnet-4)")
print(f" Savings: {((baseline - optimized) / baseline * 100):.1f}%")
print()
avg_savings = ((total_baseline - total_optimized) / total_baseline * 100)
print(f"Average savings: {avg_savings:.1f}%")
print()
# Extrapolate to monthly volume
monthly_incidents = 10000
l1_resolution_rate = 0.77
print(f"At {monthly_incidents:,} incidents/month with {l1_resolution_rate*100:.0f}% L1 resolution:")
baseline_monthly = (monthly_incidents * 0.77 * 3.00) + (monthly_incidents * 0.23 * 3.00)
optimized_monthly = (monthly_incidents * 0.77 * 0.15) + (monthly_incidents * 0.23 * 3.00)
print(f" Without routing: ${baseline_monthly:,.0f}/month")
print(f" With routing: ${optimized_monthly:,.0f}/month")
print(f" Monthly savings: ${baseline_monthly - optimized_monthly:,.0f}")
print(f" Annual savings: ${(baseline_monthly - optimized_monthly) * 12:,.0f}")
print()
if __name__ == '__main__':
# Set dummy endpoint for testing
os.environ['AZURE_OPENAI_ENDPOINT'] = 'https://example.openai.azure.com'
test_routing()