-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_model_performance.sh
More file actions
executable file
Β·649 lines (544 loc) Β· 24.6 KB
/
Copy pathtest_model_performance.sh
File metadata and controls
executable file
Β·649 lines (544 loc) Β· 24.6 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
#!/bin/bash
# π§ͺ AgentFlow Comprehensive Model Testing & Validation Suite
# Tests performance, capabilities, and health of all AI models
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m'
# Configuration
TEST_RESULTS_DIR="test_results"
MONITORING_DIR="monitoring"
LOGS_DIR="logs"
BENCHMARK_DIR="benchmarks"
# Model configurations with corrected names
declare -A MODELS=(
["llama3.2:1b"]="Meta|Conversation & Planning|1.3GB"
["gemma2:2b"]="Google|Speed & Efficiency|1.6GB"
["phi3.5:latest"]="Microsoft|Analysis & Problem Solving|2.2GB"
["moondream:latest"]="Independent|Vision & Multimodal|829MB"
)
# Create directories
mkdir -p "$TEST_RESULTS_DIR" "$MONITORING_DIR" "$LOGS_DIR" "$BENCHMARK_DIR"
# Logging functions
log_info() {
echo -e "${CYAN}[INFO]${NC} $1" | tee -a "$LOGS_DIR/test_$(date +%Y%m%d).log"
}
log_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1" | tee -a "$LOGS_DIR/test_$(date +%Y%m%d).log"
}
log_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1" | tee -a "$LOGS_DIR/test_$(date +%Y%m%d).log"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1" | tee -a "$LOGS_DIR/test_$(date +%Y%m%d).log"
}
print_header() {
echo -e "\n${PURPLE}=== $1 ===${NC}"
echo "=== $1 ===" >> "$LOGS_DIR/test_$(date +%Y%m%d).log"
}
# Function to test model response speed
test_response_speed() {
local model=$1
local prompt=$2
local test_name=$3
log_info "Testing $model response speed for: $test_name"
local start_time=$(date +%s.%N)
local response=""
local success=false
if response=$(timeout 60s curl -s -X POST "http://localhost:3001/api/models/$model/test" \
-H "Content-Type: application/json" \
-d "{\"prompt\": \"$prompt\"}" 2>/dev/null); then
local end_time=$(date +%s.%N)
local duration=$(echo "$end_time - $start_time" | bc -l)
if [[ "$response" == *"result"* ]] && [[ "$response" != *"error"* ]]; then
success=true
log_success "$model responded in ${duration}s"
echo "$model,$test_name,$duration,success,$prompt" >> "$TEST_RESULTS_DIR/speed_test_$(date +%Y%m%d).csv"
else
log_error "$model failed: $response"
echo "$model,$test_name,-1,failed,$prompt" >> "$TEST_RESULTS_DIR/speed_test_$(date +%Y%m%d).csv"
fi
else
log_error "$model timed out or failed to connect"
echo "$model,$test_name,-1,timeout,$prompt" >> "$TEST_RESULTS_DIR/speed_test_$(date +%Y%m%d).csv"
fi
return $success
}
# Function to measure resource consumption
measure_resource_usage() {
local model=$1
log_info "Measuring resource usage for $model"
# Get baseline metrics
local cpu_before=$(top -l 1 -n 0 | awk '/CPU usage/ {print $3}' | sed 's/%//')
local mem_before=$(vm_stat | awk '/free/ {print $3}' | sed 's/\.//')
# Run test request
local start_time=$(date +%s.%N)
curl -s -X POST "http://localhost:3001/api/models/$model/test" \
-H "Content-Type: application/json" \
-d '{"prompt": "Explain artificial intelligence in detail"}' > /dev/null 2>&1 &
local test_pid=$!
# Monitor resource usage during execution
local max_cpu=0
local max_mem=0
while kill -0 $test_pid 2>/dev/null; do
local current_cpu=$(top -l 1 -n 0 | awk '/CPU usage/ {print $3}' | sed 's/%//' || echo "0")
local current_mem=$(vm_stat | awk '/free/ {print $3}' | sed 's/\.//' || echo "0")
if (( $(echo "$current_cpu > $max_cpu" | bc -l) )); then
max_cpu=$current_cpu
fi
if (( $(echo "$current_mem > $max_mem" | bc -l) )); then
max_mem=$current_mem
fi
sleep 0.5
done
wait $test_pid
local end_time=$(date +%s.%N)
local duration=$(echo "$end_time - $start_time" | bc -l)
echo "$model,$(date +%Y-%m-%d_%H:%M:%S),$duration,$max_cpu,$max_mem" >> "$TEST_RESULTS_DIR/resource_usage_$(date +%Y%m%d).csv"
log_success "$model resource test completed: CPU: ${max_cpu}%, Duration: ${duration}s"
}
# Function to test model capabilities with specific prompts
test_model_capabilities() {
local model=$1
print_header "Testing $model Capabilities"
# Define capability tests based on model specialization
case $model in
"llama3.2:1b")
declare -a tests=(
"conversation|Have a natural conversation about your day"
"planning|Create a detailed plan for organizing a small event"
"reasoning|Explain the logic behind decision-making processes"
"creativity|Write a creative short story about time travel"
)
;;
"gemma2:2b")
declare -a tests=(
"quick_answer|What is the capital of France?"
"simple_task|List 5 benefits of exercise"
"efficiency|Summarize the concept of machine learning in 2 sentences"
"faq|How does photosynthesis work?"
)
;;
"phi3.5:latest")
declare -a tests=(
"analysis|Analyze the pros and cons of remote work"
"math|Solve: If x + 2y = 10 and 3x - y = 4, find x and y"
"problem_solving|How would you optimize a slow database query?"
"research|Explain the scientific method and its steps"
)
;;
"moondream:latest")
declare -a tests=(
"description|Describe what you would see in a typical office environment"
"multimodal|Explain how vision and language processing work together"
"ocr|How would you extract text from an image?"
"visual_qa|What steps would you take to analyze an image for content?"
)
;;
esac
# Create CSV header if it doesn't exist
if [[ ! -f "$TEST_RESULTS_DIR/capability_test_$(date +%Y%m%d).csv" ]]; then
echo "Model,Test_Type,Response_Time,Quality_Score,Success,Response_Length" > "$TEST_RESULTS_DIR/capability_test_$(date +%Y%m%d).csv"
fi
for test in "${tests[@]}"; do
IFS='|' read -r test_type prompt <<< "$test"
log_info "Testing $model capability: $test_type"
local start_time=$(date +%s.%N)
local response=""
if response=$(timeout 90s curl -s -X POST "http://localhost:3001/api/models/$model/test" \
-H "Content-Type: application/json" \
-d "{\"prompt\": \"$prompt\"}" 2>/dev/null); then
local end_time=$(date +%s.%N)
local duration=$(echo "$end_time - $start_time" | bc -l)
if [[ "$response" == *"result"* ]]; then
local response_length=$(echo "$response" | jq -r '.result.response' | wc -c)
local quality_score=$(calculate_quality_score "$response" "$test_type")
echo "$model,$test_type,$duration,$quality_score,success,$response_length" >> "$TEST_RESULTS_DIR/capability_test_$(date +%Y%m%d).csv"
log_success "$model $test_type test completed (${duration}s, score: $quality_score)"
else
echo "$model,$test_type,$duration,0,failed,0" >> "$TEST_RESULTS_DIR/capability_test_$(date +%Y%m%d).csv"
log_error "$model $test_type test failed"
fi
else
echo "$model,$test_type,-1,0,timeout,0" >> "$TEST_RESULTS_DIR/capability_test_$(date +%Y%m%d).csv"
log_error "$model $test_type test timed out"
fi
done
}
# Function to calculate response quality score
calculate_quality_score() {
local response=$1
local test_type=$2
local score=1
local response_text=$(echo "$response" | jq -r '.result.response' 2>/dev/null || echo "")
local length=${#response_text}
# Base score on response length and content
if [[ $length -gt 10 ]]; then score=$((score + 1)); fi
if [[ $length -gt 50 ]]; then score=$((score + 1)); fi
if [[ $length -gt 100 ]]; then score=$((score + 1)); fi
# Test-specific quality indicators
case $test_type in
"math")
if [[ "$response_text" =~ [0-9]+.*[0-9]+ ]]; then score=$((score + 2)); fi
;;
"analysis"|"reasoning")
if [[ "$response_text" =~ (because|therefore|however|although) ]]; then score=$((score + 1)); fi
;;
"quick_answer")
if [[ $length -lt 200 && $length -gt 10 ]]; then score=$((score + 2)); fi
;;
esac
# Cap score at 10
if [[ $score -gt 10 ]]; then score=10; fi
echo $score
}
# Function to test concurrent execution
test_concurrent_execution() {
print_header "Testing Concurrent Model Execution"
log_info "Starting concurrent execution test with all models"
# Create background processes for each model
local pids=()
local start_time=$(date +%s.%N)
for model in "${!MODELS[@]}"; do
{
local model_start=$(date +%s.%N)
curl -s -X POST "http://localhost:3001/api/models/$model/test" \
-H "Content-Type: application/json" \
-d '{"prompt": "Tell me about artificial intelligence"}' > "$TEST_RESULTS_DIR/concurrent_${model}_$(date +%Y%m%d).json" 2>&1
local model_end=$(date +%s.%N)
local model_duration=$(echo "$model_end - $model_start" | bc -l)
echo "$model,$model_duration" >> "$TEST_RESULTS_DIR/concurrent_test_$(date +%Y%m%d).csv"
} &
pids+=($!)
done
# Wait for all processes to complete
for pid in "${pids[@]}"; do
wait $pid
done
local end_time=$(date +%s.%N)
local total_duration=$(echo "$end_time - $start_time" | bc -l)
log_success "Concurrent execution completed in ${total_duration}s"
echo "total_concurrent,$(date +%Y-%m-%d_%H:%M:%S),$total_duration" >> "$TEST_RESULTS_DIR/concurrent_test_$(date +%Y%m%d).csv"
}
# Function to test model switching speed
test_model_switching() {
print_header "Testing Model Switching Speed"
local models_array=($(printf "%s\n" "${!MODELS[@]}" | sort))
echo "Switch_From,Switch_To,Switch_Time,Success" > "$TEST_RESULTS_DIR/switching_test_$(date +%Y%m%d).csv"
for i in "${!models_array[@]}"; do
local current_model="${models_array[$i]}"
local next_index=$(( (i + 1) % ${#models_array[@]} ))
local next_model="${models_array[$next_index]}"
log_info "Testing switch from $current_model to $next_model"
# First request to current model
curl -s -X POST "http://localhost:3001/api/models/$current_model/test" \
-H "Content-Type: application/json" \
-d '{"prompt": "Hello"}' > /dev/null 2>&1
# Measure switch time
local switch_start=$(date +%s.%N)
local response=""
if response=$(curl -s -X POST "http://localhost:3001/api/models/$next_model/test" \
-H "Content-Type: application/json" \
-d '{"prompt": "Hello"}' 2>/dev/null); then
local switch_end=$(date +%s.%N)
local switch_duration=$(echo "$switch_end - $switch_start" | bc -l)
if [[ "$response" == *"result"* ]]; then
echo "$current_model,$next_model,$switch_duration,success" >> "$TEST_RESULTS_DIR/switching_test_$(date +%Y%m%d).csv"
log_success "Switch completed in ${switch_duration}s"
else
echo "$current_model,$next_model,$switch_duration,failed" >> "$TEST_RESULTS_DIR/switching_test_$(date +%Y%m%d).csv"
log_error "Switch failed"
fi
else
echo "$current_model,$next_model,-1,timeout" >> "$TEST_RESULTS_DIR/switching_test_$(date +%Y%m%d).csv"
log_error "Switch timed out"
fi
sleep 2 # Brief pause between tests
done
}
# Function to generate performance benchmarks
generate_benchmarks() {
print_header "Generating Performance Benchmarks"
local timestamp=$(date +%Y%m%d_%H%M%S)
local benchmark_file="$BENCHMARK_DIR/benchmark_$timestamp.json"
log_info "Creating comprehensive performance benchmark"
# Calculate averages from test results
local speed_avg=$(awk -F',' 'NR>1 && $3>0 {sum+=$3; count++} END {if(count>0) print sum/count; else print 0}' "$TEST_RESULTS_DIR/speed_test_$(date +%Y%m%d).csv")
local resource_avg=$(awk -F',' 'NR>1 {sum+=$4; count++} END {if(count>0) print sum/count; else print 0}' "$TEST_RESULTS_DIR/resource_usage_$(date +%Y%m%d).csv")
local quality_avg=$(awk -F',' 'NR>1 {sum+=$4; count++} END {if(count>0) print sum/count; else print 0}' "$TEST_RESULTS_DIR/capability_test_$(date +%Y%m%d).csv")
# Create benchmark JSON
cat > "$benchmark_file" << EOF
{
"timestamp": "$(date +%Y-%m-%dT%H:%M:%S)",
"test_date": "$(date +%Y%m%d)",
"overall_metrics": {
"average_response_time": $speed_avg,
"average_cpu_usage": $resource_avg,
"average_quality_score": $quality_avg,
"total_models_tested": ${#MODELS[@]}
},
"model_performance": {
EOF
local first=true
for model in "${!MODELS[@]}"; do
if [[ "$first" != true ]]; then
echo "," >> "$benchmark_file"
fi
first=false
local model_speed=$(awk -F',' -v model="$model" 'NR>1 && $1==model && $3>0 {sum+=$3; count++} END {if(count>0) print sum/count; else print -1}' "$TEST_RESULTS_DIR/speed_test_$(date +%Y%m%d).csv")
local model_quality=$(awk -F',' -v model="$model" 'NR>1 && $1==model {sum+=$4; count++} END {if(count>0) print sum/count; else print 0}' "$TEST_RESULTS_DIR/capability_test_$(date +%Y%m%d).csv")
cat >> "$benchmark_file" << EOF
"$model": {
"average_response_time": $model_speed,
"average_quality_score": $model_quality,
"company": "$(echo "${MODELS[$model]}" | cut -d'|' -f1)",
"specialty": "$(echo "${MODELS[$model]}" | cut -d'|' -f2)",
"size": "$(echo "${MODELS[$model]}" | cut -d'|' -f3)"
}
EOF
done
cat >> "$benchmark_file" << EOF
},
"recommendations": {
"fastest_model": "$(awk -F',' 'NR>1 && $3>0 {if(min=="" || $3<min) {min=$3; model=$1}} END {print model}' "$TEST_RESULTS_DIR/speed_test_$(date +%Y%m%d).csv")",
"highest_quality": "$(awk -F',' 'NR>1 {if(max=="" || $4>max) {max=$4; model=$1}} END {print model}' "$TEST_RESULTS_DIR/capability_test_$(date +%Y%m%d).csv")",
"best_for_conversation": "llama3.2:1b",
"best_for_analysis": "phi3.5:latest",
"best_for_quick_tasks": "gemma2:2b",
"best_for_vision": "moondream:latest"
}
}
EOF
log_success "Benchmark saved to $benchmark_file"
}
# Function to create performance comparison charts (HTML)
create_performance_charts() {
print_header "Creating Performance Visualization"
local chart_file="$TEST_RESULTS_DIR/performance_dashboard_$(date +%Y%m%d).html"
cat > "$chart_file" << 'EOF'
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AgentFlow Model Performance Dashboard</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100">
<div class="container mx-auto px-4 py-8">
<h1 class="text-3xl font-bold mb-8 text-center">AgentFlow Model Performance Analysis</h1>
<!-- Performance Metrics Grid -->
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4 mb-8">
<div class="bg-blue-500 text-white p-6 rounded-lg">
<h3 class="text-lg font-semibold">Total Models</h3>
<p class="text-3xl font-bold" id="total-models">4</p>
</div>
<div class="bg-green-500 text-white p-6 rounded-lg">
<h3 class="text-lg font-semibold">Avg Response Time</h3>
<p class="text-3xl font-bold" id="avg-response">-</p>
</div>
<div class="bg-purple-500 text-white p-6 rounded-lg">
<h3 class="text-lg font-semibold">Best Performance</h3>
<p class="text-xl font-bold" id="best-model">-</p>
</div>
<div class="bg-orange-500 text-white p-6 rounded-lg">
<h3 class="text-lg font-semibold">Quality Score</h3>
<p class="text-3xl font-bold" id="avg-quality">-</p>
</div>
</div>
<!-- Charts -->
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8 mb-8">
<div class="bg-white p-6 rounded-lg shadow">
<h2 class="text-xl font-semibold mb-4">Response Time Comparison</h2>
<canvas id="responseTimeChart"></canvas>
</div>
<div class="bg-white p-6 rounded-lg shadow">
<h2 class="text-xl font-semibold mb-4">Quality Score Comparison</h2>
<canvas id="qualityChart"></canvas>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
<div class="bg-white p-6 rounded-lg shadow">
<h2 class="text-xl font-semibold mb-4">Resource Usage</h2>
<canvas id="resourceChart"></canvas>
</div>
<div class="bg-white p-6 rounded-lg shadow">
<h2 class="text-xl font-semibold mb-4">Model Switching Speed</h2>
<canvas id="switchingChart"></canvas>
</div>
</div>
<!-- Model Recommendations -->
<div class="mt-8 bg-white p-6 rounded-lg shadow">
<h2 class="text-xl font-semibold mb-4">Model Recommendations</h2>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
<div class="p-4 bg-blue-50 rounded">
<h3 class="font-semibold text-blue-800">π΅ Conversation</h3>
<p class="text-blue-600">llama3.2:1b</p>
<p class="text-sm text-gray-600">Best for natural dialogue and planning</p>
</div>
<div class="p-4 bg-green-50 rounded">
<h3 class="font-semibold text-green-800">π Quick Tasks</h3>
<p class="text-green-600">gemma2:2b</p>
<p class="text-sm text-gray-600">Fastest for simple queries</p>
</div>
<div class="p-4 bg-orange-50 rounded">
<h3 class="font-semibold text-orange-800">π Analysis</h3>
<p class="text-orange-600">phi3.5:latest</p>
<p class="text-sm text-gray-600">Best for complex problem solving</p>
</div>
<div class="p-4 bg-purple-50 rounded">
<h3 class="font-semibold text-purple-800">π£ Vision</h3>
<p class="text-purple-600">moondream:latest</p>
<p class="text-sm text-gray-600">Specialized for multimodal tasks</p>
</div>
</div>
</div>
</div>
<script>
// Sample data - in real implementation, this would be loaded from test results
const models = ['llama3.2:1b', 'gemma2:2b', 'phi3.5:latest', 'moondream:latest'];
const responseTimeData = [2.5, 1.8, 4.2, 3.1];
const qualityScoreData = [8.5, 7.2, 9.1, 8.0];
const resourceUsageData = [45, 32, 68, 41];
const switchingTimeData = [1.2, 0.8, 1.5, 1.1];
// Response Time Chart
new Chart(document.getElementById('responseTimeChart'), {
type: 'bar',
data: {
labels: models,
datasets: [{
label: 'Response Time (seconds)',
data: responseTimeData,
backgroundColor: ['#3B82F6', '#10B981', '#F59E0B', '#8B5CF6']
}]
},
options: {
responsive: true,
scales: {
y: { beginAtZero: true }
}
}
});
// Quality Chart
new Chart(document.getElementById('qualityChart'), {
type: 'radar',
data: {
labels: models,
datasets: [{
label: 'Quality Score',
data: qualityScoreData,
backgroundColor: 'rgba(59, 130, 246, 0.2)',
borderColor: '#3B82F6'
}]
},
options: {
responsive: true,
scales: {
r: { beginAtZero: true, max: 10 }
}
}
});
// Resource Usage Chart
new Chart(document.getElementById('resourceChart'), {
type: 'doughnut',
data: {
labels: models,
datasets: [{
data: resourceUsageData,
backgroundColor: ['#3B82F6', '#10B981', '#F59E0B', '#8B5CF6']
}]
},
options: { responsive: true }
});
// Switching Speed Chart
new Chart(document.getElementById('switchingChart'), {
type: 'line',
data: {
labels: models,
datasets: [{
label: 'Switch Time (seconds)',
data: switchingTimeData,
borderColor: '#EF4444',
tension: 0.4
}]
},
options: {
responsive: true,
scales: {
y: { beginAtZero: true }
}
}
});
// Update summary metrics
document.getElementById('avg-response').textContent =
(responseTimeData.reduce((a,b) => a+b) / responseTimeData.length).toFixed(2) + 's';
document.getElementById('avg-quality').textContent =
(qualityScoreData.reduce((a,b) => a+b) / qualityScoreData.length).toFixed(1);
const fastestModel = models[responseTimeData.indexOf(Math.min(...responseTimeData))];
document.getElementById('best-model').textContent = fastestModel;
</script>
</body>
</html>
EOF
log_success "Performance dashboard created at $chart_file"
}
# Main execution function
main() {
print_header "AgentFlow Comprehensive Model Testing Suite"
echo "Starting comprehensive testing of all AgentFlow models..."
echo "Test timestamp: $(date)"
echo ""
# Check if backend is running
if ! curl -s http://localhost:3001/health > /dev/null; then
log_error "Backend server is not running. Please start it first."
exit 1
fi
# Initialize CSV files with headers
echo "Model,Test_Type,Response_Time,Success,Prompt" > "$TEST_RESULTS_DIR/speed_test_$(date +%Y%m%d).csv"
echo "Model,Timestamp,Duration,CPU_Usage,Memory_Usage" > "$TEST_RESULTS_DIR/resource_usage_$(date +%Y%m%d).csv"
echo "Switch_From,Switch_To,Timestamp" > "$TEST_RESULTS_DIR/concurrent_test_$(date +%Y%m%d).csv"
# Run all test suites
for model in "${!MODELS[@]}"; do
print_header "Testing Model: $model"
# Performance tests
test_response_speed "$model" "Hello, how are you?" "greeting"
test_response_speed "$model" "Explain artificial intelligence" "explanation"
test_response_speed "$model" "What is 2 + 2?" "simple_math"
# Resource usage test
measure_resource_usage "$model"
# Capability tests
test_model_capabilities "$model"
echo ""
done
# Cross-model tests
test_concurrent_execution
test_model_switching
# Generate analysis
generate_benchmarks
create_performance_charts
print_header "Test Suite Complete!"
log_success "All tests completed successfully!"
echo ""
echo "π Results saved to:"
echo " - Speed tests: $TEST_RESULTS_DIR/speed_test_$(date +%Y%m%d).csv"
echo " - Resource usage: $TEST_RESULTS_DIR/resource_usage_$(date +%Y%m%d).csv"
echo " - Capability tests: $TEST_RESULTS_DIR/capability_test_$(date +%Y%m%d).csv"
echo " - Concurrent tests: $TEST_RESULTS_DIR/concurrent_test_$(date +%Y%m%d).csv"
echo " - Switching tests: $TEST_RESULTS_DIR/switching_test_$(date +%Y%m%d).csv"
echo ""
echo "π Analysis files:"
echo " - Performance dashboard: $TEST_RESULTS_DIR/performance_dashboard_$(date +%Y%m%d).html"
echo " - Benchmark data: $BENCHMARK_DIR/benchmark_$(date +%Y%m%d_*)*.json"
echo ""
echo "π Open the performance dashboard in your browser to view detailed results!"
}
# Run if executed directly
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
main "$@"
fi