Skip to content
This repository was archived by the owner on Feb 18, 2025. It is now read-only.

Commit 3c5f9a3

Browse files
abby didnt like us using his api that he made for testing so we change back to slow method i guess
1 parent f1b4632 commit 3c5f9a3

File tree

1 file changed

+41
-32
lines changed

1 file changed

+41
-32
lines changed

js/status.js

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const api_url_models = 'https://penguinai.milosantos.com/v1/models';
2-
const api_url_model_status = 'https://penguinai.milosantos.com/v1/api/working?model=';
2+
const api_url_chat_completions = 'https://penguinai.milosantos.com/v1/chat/completions';
33

44
async function fetchAndGetReqModels() {
55
try {
@@ -55,48 +55,57 @@ async function displayModels() {
5555
statusTable.appendChild(row);
5656
});
5757

58-
checkModelStatus(models);
58+
checkModelStatusInBatches(models);
5959
}
6060

61-
async function checkModelStatus(models) {
61+
async function checkModelStatusInBatches(models) {
62+
const batchSize = 5;
6263
let failed = 0;
6364
let checked = 0;
64-
let total = models.length;
65+
const total = models.length;
6566
const statusText = document.getElementById('model-status-progress');
6667
let statusTextCopy = "Models Status:\n";
67-
const updateInterval = 5; // Update status text after every 5 models
6868

69-
for (const [index, model] of models.entries()) {
70-
const statusCell = document.getElementById(`status-${model.value}`);
71-
72-
try {
73-
const response = await fetch(api_url_model_status + model.value);
74-
const data = await response.text();
75-
76-
checked++;
77-
78-
if (data === "True") {
79-
statusCell.textContent = '✅ Up'; // Checkmark for successful status
80-
statusTextCopy += `${model.text} >> ✅ Up\n`;
81-
} else {
82-
statusCell.textContent = '❌ Down';
83-
statusTextCopy += `${model.text} >> ❌ Down\n`;
69+
for (let i = 0; i < total; i += batchSize) {
70+
const batch = models.slice(i, i + batchSize);
71+
await Promise.all(batch.map(async (model) => {
72+
const statusCell = document.getElementById(`status-${model.value}`);
73+
try {
74+
const response = await fetch(api_url_chat_completions, {
75+
method: 'POST',
76+
headers: {
77+
'Content-Type': 'application/json',
78+
},
79+
body: JSON.stringify({
80+
model: model.value,
81+
messages: [{ role: "user", content: "hi" }]
82+
}),
83+
});
84+
85+
checked++;
86+
87+
if (response.ok) {
88+
statusCell.textContent = '✅ Up'; // Checkmark for successful status
89+
statusTextCopy += `${model.text} >> ✅ Up\n`;
90+
} else {
91+
statusCell.textContent = `❌ Down`;
92+
statusTextCopy += `${model.text} >> ❌ Down\n`;
93+
failed++;
94+
}
95+
} catch (error) {
96+
const errorMessage = error.message || 'Unknown error';
97+
statusCell.textContent = `❌ Error: ${errorMessage}`;
98+
statusTextCopy += `${model.text} >> ❌ Error: ${errorMessage}\n`;
8499
failed++;
85100
}
86-
} catch (error) {
87-
const errorMessage = error.message || 'Unknown error';
88-
statusCell.textContent = `❌ Error: ${errorMessage}`;
89-
statusTextCopy += `${model.text} >> ❌ Error: ${errorMessage}\n`;
90-
failed++;
91-
}
101+
}));
92102

93-
if ((index + 1) % updateInterval === 0 || checked === total) {
94-
let successfulProc = Math.round(((total - failed) / total) * 100);
95-
let failedProc = Math.round((failed / total) * 100);
96-
let checkedProc = Math.round((checked / total) * 100);
97-
statusText.textContent = `Total models: ${total} | Checked: ${checked} (${checkedProc}%) | Successful: ${total - failed} (${successfulProc}%) | Failed: ${failed} (${failedProc}%)`;
98-
}
103+
let successfulProc = Math.round(((total - failed) / total) * 100);
104+
let failedProc = Math.round((failed / total) * 100);
105+
let checkedProc = Math.round((checked / total) * 100);
106+
statusText.textContent = `Total models: ${total} | Checked: ${checked} (${checkedProc}%) | Successful: ${total - failed} (${successfulProc}%) | Failed: ${failed} (${failedProc}%)`;
99107
}
108+
100109
statusTextCopy += `\nTotal models: ${total} | Checked: ${checked} | Successful: ${total - failed} | Failed: ${failed}`;
101110
statusTextCopy += "\nCheck again here: https://mestai.online/status/";
102111

0 commit comments

Comments
 (0)