|
1 | 1 | 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'; |
3 | 3 |
|
4 | 4 | async function fetchAndGetReqModels() { |
5 | 5 | try { |
@@ -55,48 +55,57 @@ async function displayModels() { |
55 | 55 | statusTable.appendChild(row); |
56 | 56 | }); |
57 | 57 |
|
58 | | - checkModelStatus(models); |
| 58 | + checkModelStatusInBatches(models); |
59 | 59 | } |
60 | 60 |
|
61 | | -async function checkModelStatus(models) { |
| 61 | +async function checkModelStatusInBatches(models) { |
| 62 | + const batchSize = 5; |
62 | 63 | let failed = 0; |
63 | 64 | let checked = 0; |
64 | | - let total = models.length; |
| 65 | + const total = models.length; |
65 | 66 | const statusText = document.getElementById('model-status-progress'); |
66 | 67 | let statusTextCopy = "Models Status:\n"; |
67 | | - const updateInterval = 5; // Update status text after every 5 models |
68 | 68 |
|
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`; |
84 | 99 | failed++; |
85 | 100 | } |
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 | + })); |
92 | 102 |
|
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}%)`; |
99 | 107 | } |
| 108 | + |
100 | 109 | statusTextCopy += `\nTotal models: ${total} | Checked: ${checked} | Successful: ${total - failed} | Failed: ${failed}`; |
101 | 110 | statusTextCopy += "\nCheck again here: https://mestai.online/status/"; |
102 | 111 |
|
|
0 commit comments