Skip to content

Commit

Permalink
fix: only show playground button for models that are available
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarrazin committed Nov 5, 2024
1 parent d6dc46a commit 54297d0
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions src/lib/server/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,40 +337,25 @@ const addEndpoint = (m: Awaited<ReturnType<typeof processModel>>) => ({
},
});

const hasInferenceAPI = async (m: Awaited<ReturnType<typeof processModel>>) => {
if (!isHuggingChat) {
return false;
}

let r: Response;
try {
r = await fetch(`https://huggingface.co/api/models/${m.id}`);
} catch (e) {
console.log(e);
return false;
}

if (!r.ok) {
logger.warn(`Failed to check if ${m.id} has inference API: ${r.statusText}`);
return false;
}

const json = await r.json();

if (json.cardData.inference === false) {
return false;
}

return true;
};
const inferenceApiIds = isHuggingChat
? await fetch(
"https://huggingface.co/api/models?pipeline_tag=text-generation&inference=warm&filter=conversational"
)
.then((r) => r.json())
.then((json) => json.map((r: { id: string }) => r.id))
.catch((err) => {
logger.error(err, "Failed to fetch inference API ids");
return [];
})
: [];

export const models = await Promise.all(
modelsRaw.map((e) =>
processModel(e)
.then(addEndpoint)
.then(async (m) => ({
...m,
hasInferenceAPI: await hasInferenceAPI(m),
hasInferenceAPI: inferenceApiIds.includes(m.id ?? m.name),
}))
)
);
Expand Down

0 comments on commit 54297d0

Please sign in to comment.