Update server.js
Browse files
server.js
CHANGED
|
@@ -53,9 +53,10 @@ const PROVIDERS = [
|
|
| 53 |
url: "https://oai.endpoints.kepler.ai.cloud.ovh.net/v1/chat/completions"
|
| 54 |
},
|
| 55 |
{
|
| 56 |
-
// Proveedor público alternativo
|
| 57 |
-
id: "
|
| 58 |
-
url: "https://
|
|
|
|
| 59 |
}
|
| 60 |
];
|
| 61 |
|
|
@@ -63,7 +64,7 @@ const PROVIDERS = [
|
|
| 63 |
// Ahora el proxy dejará pasar todo el tráfico y el proveedor final aplicará el rate limit por IP.
|
| 64 |
const MAX_PER_PROVIDER = 500;
|
| 65 |
const QUEUE_TIMEOUT = 45000;
|
| 66 |
-
let currentLoad = { "pollinations-ai": 0, "kepler-cloud": 0, "
|
| 67 |
|
| 68 |
// --- RATE LIMITING LOCAL ---
|
| 69 |
const limiter = rateLimit({
|
|
@@ -107,9 +108,19 @@ async function fetchAllModels() {
|
|
| 107 |
let modelsArray = Array.isArray(json) ? json : (json && Array.isArray(json.data) ? json.data : []);
|
| 108 |
|
| 109 |
if (modelsArray.length > 0) {
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
}
|
| 114 |
return [];
|
| 115 |
} catch (error) {
|
|
@@ -123,12 +134,13 @@ async function fetchAllModels() {
|
|
| 123 |
if (result.status === "fulfilled") allModels = allModels.concat(result.value);
|
| 124 |
});
|
| 125 |
|
|
|
|
| 126 |
if (allModels.length === 0) {
|
| 127 |
allModels = [
|
| 128 |
{ id: "gpt-4o", object: "model", type: "text", owned_by: "pollinations-ai" },
|
| 129 |
{ id: "claude-3-5-sonnet", object: "model", type: "text", owned_by: "pollinations-ai" },
|
| 130 |
-
{ id: "gemini-1.5-pro", object: "model", type: "text", owned_by: "
|
| 131 |
-
{ id: "gemini-1.5-flash", object: "model", type: "text", owned_by: "
|
| 132 |
];
|
| 133 |
}
|
| 134 |
return allModels;
|
|
|
|
| 53 |
url: "https://oai.endpoints.kepler.ai.cloud.ovh.net/v1/chat/completions"
|
| 54 |
},
|
| 55 |
{
|
| 56 |
+
// Proveedor público alternativo "Airforce" (reemplaza a churchless)
|
| 57 |
+
id: "airforce-api",
|
| 58 |
+
url: "https://api.airforce/v1/chat/completions",
|
| 59 |
+
modelsUrl: "https://api.airforce/v1/models"
|
| 60 |
}
|
| 61 |
];
|
| 62 |
|
|
|
|
| 64 |
// Ahora el proxy dejará pasar todo el tráfico y el proveedor final aplicará el rate limit por IP.
|
| 65 |
const MAX_PER_PROVIDER = 500;
|
| 66 |
const QUEUE_TIMEOUT = 45000;
|
| 67 |
+
let currentLoad = { "pollinations-ai": 0, "kepler-cloud": 0, "airforce-api": 0 };
|
| 68 |
|
| 69 |
// --- RATE LIMITING LOCAL ---
|
| 70 |
const limiter = rateLimit({
|
|
|
|
| 108 |
let modelsArray = Array.isArray(json) ? json : (json && Array.isArray(json.data) ? json.data : []);
|
| 109 |
|
| 110 |
if (modelsArray.length > 0) {
|
| 111 |
+
// FILTRO: Excluir modelos de audio
|
| 112 |
+
let filteredModels = modelsArray.filter(model => !isAudioModel(model));
|
| 113 |
+
|
| 114 |
+
// 🔥 FILTRO ESPECÍFICO PARA KEPLER-CLOUD (SOLO FREE) 🔥
|
| 115 |
+
if (provider.id === "kepler-cloud") {
|
| 116 |
+
filteredModels = filteredModels.filter(model => {
|
| 117 |
+
const mId = (model.id || model.name || "").toLowerCase();
|
| 118 |
+
// Filtra si el ID incluye la palabra "free" o si tiene un flag de coste cero
|
| 119 |
+
return mId.includes("free") || model.is_free === true || model.pricing?.prompt === "0";
|
| 120 |
+
});
|
| 121 |
+
}
|
| 122 |
+
|
| 123 |
+
return filteredModels.map(model => ({ ...model, id: model.id || model.name, owned_by: provider.id }));
|
| 124 |
}
|
| 125 |
return [];
|
| 126 |
} catch (error) {
|
|
|
|
| 134 |
if (result.status === "fulfilled") allModels = allModels.concat(result.value);
|
| 135 |
});
|
| 136 |
|
| 137 |
+
// Fallback de seguridad si todas las APIs fallan al cargar modelos
|
| 138 |
if (allModels.length === 0) {
|
| 139 |
allModels = [
|
| 140 |
{ id: "gpt-4o", object: "model", type: "text", owned_by: "pollinations-ai" },
|
| 141 |
{ id: "claude-3-5-sonnet", object: "model", type: "text", owned_by: "pollinations-ai" },
|
| 142 |
+
{ id: "gemini-1.5-pro", object: "model", type: "text", owned_by: "airforce-api" },
|
| 143 |
+
{ id: "gemini-1.5-flash", object: "model", type: "text", owned_by: "airforce-api" }
|
| 144 |
];
|
| 145 |
}
|
| 146 |
return allModels;
|