-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
699 lines (642 loc) · 20.6 KB
/
index.html
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
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>status checker</title>
<!-- Meta viewport tag for responsive design -->
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
/* Reset and base styles */
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
margin: 0;
text-align: center;
font-family: Helvetica, Arial, sans-serif;
background-color: #1e1e1e;
color: #e0e0e0;
padding: 20px;
font-size: 16px; /* Set base font size */
}
h1 {
margin-bottom: 20px;
color: #ffffff;
font-size: 2rem; /* Use rem units */
white-space: nowrap;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
max-width: 800px; /* Limit the container width */
padding: 20px;
background-color: #333333;
border-radius: 8px;
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.5);
margin-bottom: 20px;
}
input, textarea {
margin: 10px 0;
padding: 12px;
font-size: 1rem;
border-radius: 5px;
background-color: #2a2a2a;
color: #e0e0e0;
border: 1px solid #555555;
width: 100%;
box-sizing: border-box;
}
button {
cursor: pointer;
background-color: #6c757d;
color: white;
border: none;
padding: 12px;
border-radius: 5px;
font-size: 1rem;
transition: background-color 0.3s;
width: 100%;
box-sizing: border-box;
margin-top: 10px;
}
button:hover {
background-color: #5a6268;
}
button:disabled {
background-color: #4e555b;
cursor: not-allowed;
}
.status {
margin-top: 20px;
width: 100%;
max-width: 800px; /* Ensure the table doesn't exceed the container width */
display: flex;
flex-direction: column;
align-items: center; /* Center the table */
}
.status h2 {
margin-bottom: 10px;
font-size: 1.5rem;
color: #ffffff;
}
/* Modified CSS for the table */
.status table {
width: 100%;
border-collapse: collapse;
border-radius: 8px;
overflow: hidden;
background-color: #333333;
}
.status th, .status td {
padding: 12px;
border: 1px solid #555555;
text-align: left;
font-size: 1rem;
}
/* Adjust column widths */
.status th.name, .status td.name {
width: 60%; /* Name column takes up 60% */
word-wrap: break-word;
}
.status th.up, .status td.up,
.status th.req, .status td.req {
width: 20%; /* Up and Req columns take up 20% each */
text-align: center;
}
.status td.up.green, .status td.req.green {
background-color: #28a745; /* Green */
color: #ffffff;
}
.status td.up.red, .status td.req.red {
background-color: #dc3545; /* Red */
color: #ffffff;
}
.status td.req.yellow {
background-color: #ffc107; /* Yellow */
color: #ffffff;
}
.status td.proxy {
background-color: #322436; /* Shade of Purple */
color: #ffffff;
font-weight: bold;
}
.message {
margin-top: 20px;
font-size: 1.1rem;
}
/* Progress Bar Styles */
.progress-wrapper {
width: 100%;
max-width: 800px;
display: none; /* Initially hidden */
align-items: center;
margin-top: 20px;
}
.progress-container {
flex: 1;
background-color: #555555;
height: 20px;
border-radius: 5px;
overflow: hidden;
}
.progress-bar {
width: 0%;
height: 100%;
background-color: #28a745;
border-radius: 5px;
transition: width 0.1s linear;
}
#cancelButton {
margin-left: 10px;
width: auto;
height: 100%;
padding: 5px 10px;
font-size: 1rem;
background-color: #dc3545;
border-radius: 5px;
cursor: pointer;
}
#cancelButton:hover {
background-color: #c82333;
}
/* Responsive Styles */
@media (max-width: 768px) {
h1 {
font-size: 2.2rem;
}
.container {
padding: 15px;
}
input, textarea {
font-size: 1.1rem;
padding: 14px;
}
button {
font-size: 1.1rem;
padding: 14px;
}
.status h2 {
font-size: 1.7rem;
}
.status th, .status td {
padding: 14px;
font-size: 1.1rem;
}
.message {
font-size: 1.2rem;
}
#cancelButton {
font-size: 0.9rem;
padding: 5px 10px;
}
}
@media (max-width: 480px) {
h1 {
font-size: 2.4rem;
}
.container {
padding: 10px;
}
input, textarea {
font-size: 1.2rem;
padding: 16px;
}
button {
font-size: 1.2rem;
padding: 16px;
}
.status h2 {
font-size: 1.8rem;
}
.status th, .status td {
padding: 16px;
font-size: 1.2rem;
}
.message {
font-size: 1.3rem;
}
#cancelButton {
font-size: 0.8rem;
padding: 4px 8px;
}
}
/* Improve touch target sizes */
button, input, textarea {
touch-action: manipulation;
}
</style>
</head>
<body>
<h1>status checker</h1>
<div class="container">
<input type="text" id="apiUrl" placeholder='Enter URL with "/v1" at the end (leave blank for default)'>
<button id="checkButton" onclick="checkStatus()">check status</button>
<!-- Progress Wrapper -->
<div class="progress-wrapper" id="progressWrapper">
<div class="progress-container" id="progressContainer">
<div class="progress-bar" id="progressBar"></div>
</div>
<button id="cancelButton" onclick="cancelStatusCheck()">Cancel</button>
</div>
</div>
<div class="status" id="status">
<h2>model status</h2>
<table id="statusTable">
<tr>
<th class="name">name</th>
<th class="up">up</th>
<th class="req">req</th>
</tr>
<!-- Rows will be added here dynamically -->
</table>
</div>
<!-- Copy Results Button -->
<button id="copyButton" onclick="copyResults()" style="display: none; width: 100%; max-width: 800px; margin-top: 20px;">copy results</button>
<script>
let currentAbortController = null;
let pendingReqCells = [];
async function getDefaultProxy(signal) {
const defaultProxyUrl = 'https://mubilop.tech/proxy';
try {
const response = await fetch(defaultProxyUrl, { signal });
if (response.ok) {
const proxy = await response.text();
return proxy.trim();
} else {
throw new Error(`Failed to retrieve default proxy: ${response.status} ${response.statusText}`);
}
} catch (error) {
if (error.name === 'AbortError') {
console.log('Default proxy fetch aborted.');
} else {
console.error('Error retrieving default proxy:', error);
alert('Error retrieving default proxy. Please enter a valid API URL.');
}
return null;
}
}
async function checkProxy(apiUrl, signal) {
try {
const response = await fetch(apiUrl, { signal });
return response.ok;
} catch (error) {
if (error.name === 'AbortError') {
console.log('Proxy check aborted.');
} else {
console.error('Error checking proxy:', error);
}
return false;
}
}
async function getModels(apiUrl, signal) {
try {
const response = await fetch(`${apiUrl}/models`, { signal });
if (response.ok) {
const data = await response.json();
return data.data || [];
} else {
console.error(`Error fetching models: ${response.status} ${response.statusText}`);
return [];
}
} catch (error) {
if (error.name === 'AbortError') {
console.log('Get models fetch aborted.');
} else {
console.error('Error fetching models:', error);
}
return [];
}
}
async function checkModelUp(apiUrl, modelId, signal) {
try {
const response = await fetch(`${apiUrl}/api/working?model=${modelId}`, { signal });
if (response.ok) {
const data = await response.text();
return data.trim().toLowerCase() === 'true';
} else {
console.error(`Error checking proxy status for model ${modelId}: ${response.status} ${response.statusText}`);
return false;
}
} catch (error) {
if (error.name === 'AbortError') {
console.log(`Proxy check for model ${modelId} aborted.`);
} else {
console.error(`Error checking proxy status for model ${modelId}:`, error);
}
return false;
}
}
async function checkModelStatus(apiUrl, modelId, upCell, reqCell, signal) {
try {
const response = await fetch(`${apiUrl}/chat/completions`, {
method: 'POST',
signal,
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: modelId,
messages: [
{ role: 'user', content: 'please output only a period "." to make sure you are online' }
]
})
});
if (response.ok) {
// As long as we get a successful response, mark as ✓
reqCell.textContent = '✓';
reqCell.classList.remove('yellow');
reqCell.classList.add('green');
// Update Up status to ✓ and green
upCell.textContent = '✓';
upCell.classList.remove('red');
upCell.classList.add('green');
} else {
console.error(`Error checking model ${modelId} status: ${response.status} ${response.statusText}`);
reqCell.textContent = '✗';
reqCell.classList.remove('yellow');
reqCell.classList.add('red');
// Update Up status to ✗ and red
upCell.textContent = '✗';
upCell.classList.remove('green');
upCell.classList.add('red');
}
} catch (error) {
if (error.name === 'AbortError') {
console.log(`Check model ${modelId} status aborted.`);
} else {
console.error(`Error checking model ${modelId} status:`, error);
reqCell.textContent = '✗';
reqCell.classList.remove('yellow');
reqCell.classList.add('red');
// Update Up status to ✗ and red
upCell.textContent = '✗';
upCell.classList.remove('green');
upCell.classList.add('red');
}
} finally {
// Remove the cell from pendingReqCells
const index = pendingReqCells.indexOf(reqCell);
if (index > -1) {
pendingReqCells.splice(index, 1);
}
}
}
function formatModelName(modelId) {
return modelId.toLowerCase();
}
async function checkStatus() {
// If there's an ongoing process, abort it
if (currentAbortController) {
currentAbortController.abort();
}
// Create a new AbortController for the new process
currentAbortController = new AbortController();
const { signal } = currentAbortController;
const apiUrlInput = document.getElementById('apiUrl').value.trim();
const statusTable = document.getElementById('statusTable');
const checkButton = document.getElementById('checkButton');
const progressWrapper = document.getElementById('progressWrapper');
const progressBar = document.getElementById('progressBar');
const cancelButton = document.getElementById('cancelButton');
const copyButton = document.getElementById('copyButton');
// Disable the button to prevent multiple clicks
checkButton.disabled = true;
// Reset progress bar
progressBar.style.width = '0%';
progressWrapper.style.display = 'flex';
cancelButton.style.display = 'block';
copyButton.style.display = 'none'; // Hide the copy button
// Clear previous status and headers
statusTable.innerHTML = `
<tr>
<th class="name">Name</th>
<th class="up">Up</th>
<th class="req">Req</th>
</tr>
`;
pendingReqCells = []; // Reset pendingReqCells
let apiUrl = apiUrlInput;
if (!apiUrl) {
apiUrl = await getDefaultProxy(signal);
if (!apiUrl) {
progressWrapper.style.display = 'none';
checkButton.disabled = false;
cancelButton.style.display = 'none';
return;
}
} else {
if (!apiUrl.startsWith('http')) {
apiUrl = 'https://' + apiUrl;
}
}
const proxyWorking = await checkProxy(apiUrl, signal);
if (signal.aborted) {
progressWrapper.style.display = 'none';
checkButton.disabled = false;
cancelButton.style.display = 'none';
return;
}
// Add Proxy status to table
const proxyRow = addRowToTable(apiUrl, proxyWorking, true);
const proxyUpCell = proxyRow.upCell;
const proxyReqCell = proxyRow.reqCell;
if (!proxyWorking) {
progressWrapper.style.display = 'none';
checkButton.disabled = false;
cancelButton.style.display = 'none';
return;
} else {
// Update proxy's "Req" cell to '✓' and make it green
proxyReqCell.textContent = '✓';
proxyReqCell.classList.add('green');
}
const models = await getModels(apiUrl, signal);
if (signal.aborted) {
progressWrapper.style.display = 'none';
checkButton.disabled = false;
cancelButton.style.display = 'none';
return;
}
// Filter out ImageGen models
const filteredModels = models.filter(model => model.type !== 'images.generations');
if (filteredModels.length === 0) {
progressWrapper.style.display = 'none';
checkButton.disabled = false;
cancelButton.style.display = 'none';
return;
}
// Prepare progress tracking
const totalModels = filteredModels.length;
let completedModels = 0;
// Set the total duration for the progress bar (in milliseconds)
const totalDuration = 102000; // 1.7 minutes = 102,000 milliseconds
const startTime = Date.now();
const updateProgressBar = () => {
const elapsedTime = Date.now() - startTime;
const estimatedCompletion = Math.min(elapsedTime / totalDuration, 1);
const progressByTime = estimatedCompletion * 100;
const progressByModels = (completedModels / totalModels) * 100;
const progress = Math.max(progressByTime, progressByModels);
progressBar.style.width = `${progress}%`;
};
// Start checking models
const modelPromises = filteredModels.map(async (model) => {
const modelId = model.id || 'unknown-id';
const modelName = formatModelName(modelId);
// Attempt to check if the model is up
const isUp = await checkModelUp(apiUrl, modelId, signal);
if (signal.aborted) {
return;
}
// Add the row to the table and get the status cells
const { upCell, reqCell } = addRowToTable(modelName, isUp, false);
// Start the prompt request regardless of isUp
await checkModelStatus(apiUrl, modelId, upCell, reqCell, signal);
// Update progress
completedModels += 1;
updateProgressBar();
});
// Periodically update the progress bar based on time
const progressInterval = setInterval(() => {
if (completedModels >= totalModels || signal.aborted) {
clearInterval(progressInterval);
return;
}
updateProgressBar();
}, 1000); // Update every second
// Wait for all model checks to complete
await Promise.all(modelPromises);
// Ensure progress bar is full
progressBar.style.width = '100%';
progressWrapper.style.display = 'none';
checkButton.disabled = false;
cancelButton.style.display = 'none';
copyButton.style.display = 'block'; // Show the copy button
}
/**
* Adds a row to the status table.
* @param {string} name - The name of the model or proxy.
* @param {boolean} isUp - Indicates if the model is up (for the "Up" column).
* @param {boolean} isProxy - Indicates if the row is for the proxy.
* @returns {Object} - Contains upCell and reqCell elements.
*/
function addRowToTable(name, isUp, isProxy) {
const statusTable = document.getElementById('statusTable');
const row = document.createElement('tr');
const nameCell = document.createElement('td');
nameCell.textContent = name;
nameCell.classList.add('name');
if (isProxy) {
nameCell.classList.add('proxy'); // Apply proxy-specific styling
}
row.appendChild(nameCell);
const upCell = document.createElement('td');
upCell.classList.add('up');
if (isProxy) {
upCell.textContent = isUp ? '✓' : '✗';
upCell.classList.add(isUp ? 'green' : 'red');
} else {
upCell.textContent = isUp ? '✓' : '✗';
upCell.classList.add(isUp ? 'green' : 'red');
}
row.appendChild(upCell);
const reqCell = document.createElement('td');
reqCell.classList.add('req');
if (isProxy) {
if (isUp) {
reqCell.textContent = '✓';
reqCell.classList.add('green');
} else {
reqCell.textContent = '✗';
reqCell.classList.add('red');
}
} else {
reqCell.textContent = '~'; // Indicates pending request
reqCell.classList.add('yellow');
pendingReqCells.push(reqCell); // Add to pendingReqCells for models
}
row.appendChild(reqCell);
statusTable.appendChild(row);
if (!isProxy) {
return { upCell, reqCell };
} else {
return { upCell, reqCell };
}
}
function cancelStatusCheck() {
if (currentAbortController) {
currentAbortController.abort();
currentAbortController = null;
// Update remaining reqCells
pendingReqCells.forEach(reqCell => {
reqCell.textContent = '✗';
reqCell.classList.remove('yellow');
reqCell.classList.add('red');
});
// Clear pendingReqCells
pendingReqCells = [];
// Update UI
const progressBar = document.getElementById('progressBar');
const progressWrapper = document.getElementById('progressWrapper');
const cancelButton = document.getElementById('cancelButton');
const copyButton = document.getElementById('copyButton');
const checkButton = document.getElementById('checkButton');
progressBar.style.width = '100%';
progressWrapper.style.display = 'none';
cancelButton.style.display = 'none';
copyButton.style.display = 'block';
checkButton.disabled = false;
}
}
function copyResults() {
const statusTable = document.getElementById('statusTable');
const rows = statusTable.querySelectorAll('tr');
let resultsText = 'model status:\n';
let totalModels = 0;
let totalUp = 0;
let successful = 0;
let failed = 0;
// Skip the header row (index 0)
for (let i = 1; i < rows.length; i++) {
const cells = rows[i].querySelectorAll('td');
const name = cells[0].textContent.trim();
const up = cells[1].textContent.trim();
const req = cells[2].textContent.trim();
// Skip the proxy row
if (cells[0].classList.contains('proxy')) {
continue;
}
totalModels += 1;
const upIcon = (up === '✓' || up === '✅') ? '✅' : '❌';
if (upIcon === '✅') totalUp += 1;
const reqIcon = (req === '✓' || req === '✅') ? '✅' : '❌';
if (reqIcon === '✅') {
successful += 1;
} else if (reqIcon === '❌') {
failed += 1;
}
const modelName = name.replace(/\s+/g, '-').toLowerCase();
resultsText += `${modelName} > ${upIcon} Up >> Req ${reqIcon}\n`;
}
resultsText += `\ntotal models: ${totalModels} | total up: ${totalUp} | successful: ${successful} | failed: ${failed}`;
// Copy resultsText to clipboard
navigator.clipboard.writeText(resultsText)
.then(() => {
alert('Results copied to clipboard.');
})
.catch(err => {
console.error('Failed to copy results:', err);
alert('Failed to copy results.');
});
}
</script>
</body>
</html>