Repository navigation
Expand file tree
/
Copy pathmodel-comparison.js
More file actions
674 lines (577 loc) · 26.2 KB
/
Copy pathmodel-comparison.js
File metadata and controls
674 lines (577 loc) · 26.2 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
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
/**
* Model Comparison Tool
* Interactive tool for comparing GGUF models based on system specifications
*/
class ModelComparisonTool {
constructor(container) {
this.container = container;
this.models = [];
this.filteredModels = [];
this.userSpecs = {};
this.init();
}
async init() {
try {
await this.loadModelData();
this.createInterface();
this.bindEvents();
this.showAllModels(); // Show all models initially
} catch (error) {
console.error('Failed to initialize model comparison tool:', error);
this.showError('Failed to load model data. Please try again later.');
}
}
async loadModelData() {
try {
const response = await fetch('/data/models.json');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
this.models = data.models || [];
this.categories = data.categories || [];
this.systemRequirements = data.systemRequirements || {};
} catch (error) {
console.error('Error loading model data:', error);
throw error;
}
}
createInterface() {
this.container.innerHTML = `
<div class="model-comparison-tool">
<header class="tool-header">
<h2>Find Your Perfect AI Model</h2>
<p>Compare GGUF models based on your system specifications and requirements</p>
</header>
<div class="tool-content">
<aside class="specs-panel">
<h3>Your System Specifications</h3>
<form class="specs-form" id="specs-form">
<div class="input-group">
<label for="ram-select">Available RAM (GB)</label>
<select id="ram-select" name="ram" required>
<option value="">Select RAM</option>
<option value="4">4 GB</option>
<option value="8">8 GB</option>
<option value="16">16 GB</option>
<option value="32">32 GB</option>
<option value="64">64 GB or more</option>
</select>
</div>
<div class="input-group">
<label for="vram-select">GPU VRAM (GB) - Optional</label>
<select id="vram-select" name="vram">
<option value="0">No GPU / CPU Only</option>
<option value="2">2 GB</option>
<option value="4">4 GB</option>
<option value="8">8 GB</option>
<option value="16">16 GB</option>
<option value="24">24 GB or more</option>
</select>
</div>
<div class="input-group">
<label for="cpu-select">CPU Type</label>
<select id="cpu-select" name="cpu">
<option value="">Select CPU</option>
<option value="basic">Basic x64 (Older processors)</option>
<option value="modern">Modern x64 (AVX2 support)</option>
<option value="high-end">High-end x64 (Latest processors)</option>
</select>
</div>
<div class="input-group">
<label for="os-select">Operating System</label>
<select id="os-select" name="os">
<option value="">Select OS</option>
<option value="windows">Windows</option>
<option value="macos">macOS</option>
<option value="linux">Linux</option>
</select>
</div>
<div class="input-group">
<label for="use-case-select">Primary Use Case</label>
<select id="use-case-select" name="useCase">
<option value="">Any use case</option>
<option value="general">General purpose</option>
<option value="coding">Code generation</option>
<option value="chat">Conversational AI</option>
<option value="research">Research & Analysis</option>
<option value="mobile">Mobile/Edge deployment</option>
</select>
</div>
<div class="button-group">
<button type="submit" class="find-models-btn">Find Compatible Models</button>
<button type="button" class="reset-btn">Reset Filters</button>
</div>
</form>
<div class="search-section">
<h4>Search Models</h4>
<div class="search-input-group">
<input type="text"
id="model-search"
placeholder="Search by name, use case, or description..."
class="search-input"
aria-label="Search models">
<button type="button" class="search-clear-btn" id="search-clear" aria-label="Clear search">
<span aria-hidden="true">✕</span>
</button>
</div>
</div>
<div class="quick-filters">
<h4>Quick Filters</h4>
<div class="filter-tags">
<button class="filter-tag" data-filter="beginner">Beginner Friendly</button>
<button class="filter-tag" data-filter="coding">Coding</button>
<button class="filter-tag" data-filter="fast">Fast Performance</button>
<button class="filter-tag" data-filter="compact">Compact Size</button>
<button class="filter-tag" data-filter="clear">Clear All</button>
</div>
</div>
</aside>
<main class="results-panel">
<div class="results-header">
<h3 id="results-title">All Available Models</h3>
<div class="results-count">
<span id="results-count">0</span> models found
</div>
</div>
<div class="results-container">
<div id="loading-indicator" class="loading-indicator" style="display: none;">
<div class="spinner"></div>
<p>Finding compatible models...</p>
</div>
<div id="error-message" class="error-message" style="display: none;"></div>
<div id="no-results" class="no-results" style="display: none;">
<h4>No compatible models found</h4>
<p>Try adjusting your system specifications or use case requirements.</p>
</div>
<div class="models-grid" id="models-grid">
<!-- Model cards will be populated here -->
</div>
</div>
</main>
</div>
</div>
`;
}
bindEvents() {
const form = this.container.querySelector('#specs-form');
const resetBtn = this.container.querySelector('.reset-btn');
const filterTags = this.container.querySelectorAll('.filter-tag');
const searchInput = this.container.querySelector('#model-search');
const searchClearBtn = this.container.querySelector('#search-clear');
form.addEventListener('submit', (e) => {
e.preventDefault();
this.handleFormSubmit();
});
resetBtn.addEventListener('click', () => {
this.resetFilters();
});
filterTags.forEach(tag => {
tag.addEventListener('click', () => {
if (tag.dataset.filter === 'clear') {
this.clearAllFilters();
} else {
this.handleQuickFilter(tag.dataset.filter);
}
});
});
// Search functionality
let searchTimeout;
searchInput.addEventListener('input', (e) => {
clearTimeout(searchTimeout);
searchTimeout = setTimeout(() => {
this.handleSearch(e.target.value);
}, 300); // Debounce search
});
searchClearBtn.addEventListener('click', () => {
searchInput.value = '';
this.handleSearch('');
});
// Real-time filtering on input change
const inputs = form.querySelectorAll('select');
inputs.forEach(input => {
input.addEventListener('change', () => {
if (this.hasAnySpecs()) {
this.handleFormSubmit();
} else {
this.applyCurrentFilters();
}
});
});
// Keyboard navigation for accessibility
searchInput.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
searchInput.value = '';
this.handleSearch('');
}
});
}
hasAnySpecs() {
const form = this.container.querySelector('#specs-form');
const formData = new FormData(form);
return Array.from(formData.values()).some(value => value !== '');
}
handleFormSubmit() {
const form = this.container.querySelector('#specs-form');
const formData = new FormData(form);
this.userSpecs = {
ram: parseInt(formData.get('ram')) || 0,
vram: parseInt(formData.get('vram')) || 0,
cpu: formData.get('cpu') || '',
os: formData.get('os') || '',
useCase: formData.get('useCase') || ''
};
this.showLoading();
// Simulate processing time for better UX
setTimeout(() => {
this.filterModels();
this.displayResults();
}, 500);
}
handleSearch(searchTerm) {
this.currentSearchTerm = searchTerm.toLowerCase().trim();
this.applyCurrentFilters();
}
applyCurrentFilters() {
this.showLoading();
setTimeout(() => {
let filtered = [...this.models];
// Apply search filter
if (this.currentSearchTerm) {
filtered = filtered.filter(model => {
const searchableText = [
model.name,
model.description,
...model.useCase,
...model.tags,
model.difficulty
].join(' ').toLowerCase();
return searchableText.includes(this.currentSearchTerm);
});
}
// Apply system specs filter if any
if (this.hasAnySpecs()) {
const form = this.container.querySelector('#specs-form');
const formData = new FormData(form);
const specs = {
ram: parseInt(formData.get('ram')) || 0,
vram: parseInt(formData.get('vram')) || 0,
cpu: formData.get('cpu') || '',
os: formData.get('os') || '',
useCase: formData.get('useCase') || ''
};
filtered = filtered.filter(model => this.isModelCompatible(model, specs));
// Sort by compatibility score
filtered.sort((a, b) => {
const scoreA = this.calculateCompatibilityScore(a, specs);
const scoreB = this.calculateCompatibilityScore(b, specs);
return scoreB - scoreA;
});
}
this.filteredModels = filtered;
this.displayResults();
// Update title based on active filters
let title = 'All Available Models';
if (this.currentSearchTerm) {
title = `Search Results for "${this.currentSearchTerm}"`;
} else if (this.hasAnySpecs()) {
title = 'Compatible Models';
}
this.updateResultsTitle(title);
}, 300);
}
handleQuickFilter(filterType) {
// Clear search when using quick filters
const searchInput = this.container.querySelector('#model-search');
searchInput.value = '';
this.currentSearchTerm = '';
this.showLoading();
setTimeout(() => {
let filtered = [...this.models];
switch (filterType) {
case 'beginner':
filtered = filtered.filter(model => model.difficulty === 'Beginner');
break;
case 'coding':
filtered = filtered.filter(model =>
model.useCase.some(use => use.toLowerCase().includes('cod'))
);
break;
case 'fast':
filtered = filtered.filter(model =>
model.performance.speed === 'Fast' || model.performance.speed === 'Very Fast'
);
break;
case 'compact':
filtered = filtered.filter(model => parseFloat(model.size) < 5);
break;
}
this.filteredModels = filtered;
this.displayResults();
this.updateResultsTitle(`${filterType.charAt(0).toUpperCase() + filterType.slice(1)} Models`);
}, 300);
}
clearAllFilters() {
// Clear search
const searchInput = this.container.querySelector('#model-search');
searchInput.value = '';
this.currentSearchTerm = '';
// Clear form
const form = this.container.querySelector('#specs-form');
form.reset();
this.userSpecs = {};
// Show all models
this.showAllModels();
}
filterModels() {
this.filteredModels = this.models.filter(model => {
return this.isModelCompatible(model, this.userSpecs);
});
// Sort by compatibility score
this.filteredModels.sort((a, b) => {
const scoreA = this.calculateCompatibilityScore(a, this.userSpecs);
const scoreB = this.calculateCompatibilityScore(b, this.userSpecs);
return scoreB - scoreA;
});
}
isModelCompatible(model, specs) {
// RAM requirement check
if (specs.ram > 0 && model.minRAM > specs.ram) {
return false;
}
// CPU requirement check
if (specs.cpu) {
const cpuCompatible = this.checkCpuCompatibility(model.cpuRequirement, specs.cpu);
if (!cpuCompatible) {
return false;
}
}
// OS compatibility check
if (specs.os) {
const osKey = specs.os.toLowerCase();
if (!model.compatibility[osKey]) {
return false;
}
}
// Use case check
if (specs.useCase) {
const hasUseCase = model.useCase.some(use =>
use.toLowerCase().includes(specs.useCase.toLowerCase())
);
if (!hasUseCase) {
return false;
}
}
return true;
}
checkCpuCompatibility(modelRequirement, userCpu) {
const cpuLevels = {
'basic': 1,
'modern': 2,
'high-end': 3
};
const modelLevel = modelRequirement.includes('High-end') ? 3 :
modelRequirement.includes('Modern') ? 2 : 1;
const userLevel = cpuLevels[userCpu] || 1;
return userLevel >= modelLevel;
}
calculateCompatibilityScore(model, specs) {
let score = 0;
// RAM efficiency score
if (specs.ram > 0) {
const ramEfficiency = specs.ram / model.recommendedRAM;
score += Math.min(ramEfficiency * 20, 30);
}
// VRAM bonus
if (specs.vram > 0 && model.recommendedVRAM > 0) {
const vramEfficiency = specs.vram / model.recommendedVRAM;
score += Math.min(vramEfficiency * 15, 20);
}
// Performance bonus
const performanceScores = {
'Very Fast': 25,
'Fast': 20,
'Medium': 15,
'Medium-Slow': 10,
'Slow': 5
};
score += performanceScores[model.performance.speed] || 10;
// Use case match bonus
if (specs.useCase) {
const hasUseCase = model.useCase.some(use =>
use.toLowerCase().includes(specs.useCase.toLowerCase())
);
if (hasUseCase) score += 15;
}
// Difficulty bonus for beginners
if (model.difficulty === 'Beginner') {
score += 10;
}
return score;
}
showAllModels() {
this.filteredModels = [...this.models];
this.displayResults();
this.updateResultsTitle('All Available Models');
}
displayResults() {
const grid = this.container.querySelector('#models-grid');
const count = this.container.querySelector('#results-count');
const noResults = this.container.querySelector('#no-results');
this.hideLoading();
count.textContent = this.filteredModels.length;
if (this.filteredModels.length === 0) {
grid.innerHTML = '';
noResults.style.display = 'block';
return;
}
noResults.style.display = 'none';
grid.innerHTML = this.filteredModels.map(model => this.createModelCard(model)).join('');
// Add click handlers for download buttons
grid.querySelectorAll('.download-btn').forEach(btn => {
btn.addEventListener('click', (e) => {
this.trackDownload(e.target.dataset.modelId);
});
});
}
createModelCard(model) {
const compatibilityScore = this.userSpecs.ram ?
this.calculateCompatibilityScore(model, this.userSpecs) : 0;
const isRecommended = compatibilityScore > 50;
const ramStatus = this.userSpecs.ram ?
(this.userSpecs.ram >= model.recommendedRAM ? 'optimal' :
this.userSpecs.ram >= model.minRAM ? 'minimum' : 'insufficient') : 'unknown';
return `
<article class="model-card ${isRecommended ? 'recommended' : ''}" data-model-id="${model.id}">
${isRecommended ? '<div class="recommended-badge">Recommended</div>' : ''}
<header class="model-header">
<h4 class="model-name">${model.name}</h4>
<div class="model-meta">
<span class="model-size">${model.size}</span>
<span class="model-difficulty difficulty-${model.difficulty.toLowerCase()}">${model.difficulty}</span>
</div>
</header>
<div class="model-description">
<p>${model.description}</p>
</div>
<div class="model-specs">
<div class="spec-item">
<span class="spec-label">RAM Required:</span>
<span class="spec-value ram-${ramStatus}">
${model.minRAM}GB min, ${model.recommendedRAM}GB recommended
</span>
</div>
<div class="spec-item">
<span class="spec-label">Performance:</span>
<span class="spec-value">${model.performance.speed} (${model.performance.tokensPerSecond} tokens/sec)</span>
</div>
<div class="spec-item">
<span class="spec-label">Context Length:</span>
<span class="spec-value">${model.performance.contextLength.toLocaleString()} tokens</span>
</div>
</div>
<div class="model-use-cases">
<span class="use-cases-label">Best for:</span>
<div class="use-cases-tags">
${model.useCase.map(use => `<span class="use-case-tag">${use}</span>`).join('')}
</div>
</div>
<div class="model-compatibility">
<div class="compatibility-icons">
${model.compatibility.windows ? '<span class="os-icon" title="Windows">🪟</span>' : ''}
${model.compatibility.macos ? '<span class="os-icon" title="macOS">🍎</span>' : ''}
${model.compatibility.linux ? '<span class="os-icon" title="Linux">🐧</span>' : ''}
${model.compatibility.arm ? '<span class="arch-icon" title="ARM Compatible">💪</span>' : ''}
</div>
<div class="gpu-requirement">
GPU: ${model.compatibility.gpu}
</div>
</div>
<footer class="model-actions">
<a href="${model.downloadUrl}"
class="download-btn"
data-model-id="${model.id}"
target="_blank"
rel="noopener noreferrer">
<span class="btn-icon">⬇️</span>
Download Model
</a>
<button class="info-btn" onclick="this.parentElement.parentElement.querySelector('.model-details').style.display = this.parentElement.parentElement.querySelector('.model-details').style.display === 'none' ? 'block' : 'none'">
<span class="btn-icon">ℹ️</span>
More Info
</button>
</footer>
<div class="model-details" style="display: none;">
<h5>Installation Instructions</h5>
<ol>
<li>Download the model file from the link above</li>
<li>Install GGUF Loader: <code>pip install ggufloader</code></li>
<li>Run: <code>ggufloader --model path/to/downloaded/model.gguf</code></li>
</ol>
<h5>Technical Details</h5>
<ul>
<li><strong>Quantization:</strong> ${model.quantization}</li>
<li><strong>Quality:</strong> ${model.performance.quality}</li>
<li><strong>CPU Requirement:</strong> ${model.cpuRequirement}</li>
${model.recommendedVRAM > 0 ? `<li><strong>Recommended VRAM:</strong> ${model.recommendedVRAM}GB</li>` : ''}
</ul>
</div>
</article>
`;
}
updateResultsTitle(title) {
const titleElement = this.container.querySelector('#results-title');
titleElement.textContent = title;
}
showLoading() {
const loading = this.container.querySelector('#loading-indicator');
const grid = this.container.querySelector('#models-grid');
const noResults = this.container.querySelector('#no-results');
loading.style.display = 'block';
grid.style.display = 'none';
noResults.style.display = 'none';
}
hideLoading() {
const loading = this.container.querySelector('#loading-indicator');
const grid = this.container.querySelector('#models-grid');
loading.style.display = 'none';
grid.style.display = 'grid';
}
showError(message) {
const error = this.container.querySelector('#error-message');
error.textContent = message;
error.style.display = 'block';
this.hideLoading();
}
resetFilters() {
const form = this.container.querySelector('#specs-form');
const searchInput = this.container.querySelector('#model-search');
form.reset();
searchInput.value = '';
this.userSpecs = {};
this.currentSearchTerm = '';
this.showAllModels();
this.updateResultsTitle('All Available Models');
}
trackDownload(modelId) {
// Analytics tracking
if (typeof gtag !== 'undefined') {
gtag('event', 'model_download', {
model_id: modelId,
page_location: window.location.href
});
}
console.log(`Model download tracked: ${modelId}`);
}
}
// Initialize the model comparison tool when DOM is ready
document.addEventListener('DOMContentLoaded', () => {
const container = document.getElementById('model-comparison-container');
if (container) {
new ModelComparisonTool(container);
}
});
// Export for module use
if (typeof module !== 'undefined' && module.exports) {
module.exports = ModelComparisonTool;
}