Spaces:
Running
Running
fix: only show playground button for models that are available
Browse files- src/lib/server/models.ts +12 -27
src/lib/server/models.ts
CHANGED
@@ -337,32 +337,17 @@ const addEndpoint = (m: Awaited<ReturnType<typeof processModel>>) => ({
|
|
337 |
},
|
338 |
});
|
339 |
|
340 |
-
const
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
}
|
352 |
-
|
353 |
-
if (!r.ok) {
|
354 |
-
logger.warn(`Failed to check if ${m.id} has inference API: ${r.statusText}`);
|
355 |
-
return false;
|
356 |
-
}
|
357 |
-
|
358 |
-
const json = await r.json();
|
359 |
-
|
360 |
-
if (json.cardData.inference === false) {
|
361 |
-
return false;
|
362 |
-
}
|
363 |
-
|
364 |
-
return true;
|
365 |
-
};
|
366 |
|
367 |
export const models = await Promise.all(
|
368 |
modelsRaw.map((e) =>
|
@@ -370,7 +355,7 @@ export const models = await Promise.all(
|
|
370 |
.then(addEndpoint)
|
371 |
.then(async (m) => ({
|
372 |
...m,
|
373 |
-
hasInferenceAPI:
|
374 |
}))
|
375 |
)
|
376 |
);
|
|
|
337 |
},
|
338 |
});
|
339 |
|
340 |
+
const inferenceApiIds = isHuggingChat
|
341 |
+
? await fetch(
|
342 |
+
"https://huggingface.co/api/models?pipeline_tag=text-generation&inference=warm&filter=conversational"
|
343 |
+
)
|
344 |
+
.then((r) => r.json())
|
345 |
+
.then((json) => json.map((r: { id: string }) => r.id))
|
346 |
+
.catch((err) => {
|
347 |
+
logger.error(err, "Failed to fetch inference API ids");
|
348 |
+
return [];
|
349 |
+
})
|
350 |
+
: [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
351 |
|
352 |
export const models = await Promise.all(
|
353 |
modelsRaw.map((e) =>
|
|
|
355 |
.then(addEndpoint)
|
356 |
.then(async (m) => ({
|
357 |
...m,
|
358 |
+
hasInferenceAPI: inferenceApiIds.includes(m.id ?? m.name),
|
359 |
}))
|
360 |
)
|
361 |
);
|