nsarrazin HF Staff commited on
Commit
451ffc4
·
unverified ·
1 Parent(s): 01b3b9f

fix: only show playground button for models that are available

Browse files
Files changed (1) hide show
  1. 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 hasInferenceAPI = async (m: Awaited<ReturnType<typeof processModel>>) => {
341
- if (!isHuggingChat) {
342
- return false;
343
- }
344
-
345
- let r: Response;
346
- try {
347
- r = await fetch(`https://huggingface.co/api/models/${m.id}`);
348
- } catch (e) {
349
- console.log(e);
350
- return false;
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: await hasInferenceAPI(m),
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
  );