scira-chat / lib /models.ts
victor's picture
victor HF Staff
feat: Add Hugging Face model support
8cfdcec
raw
history blame
733 Bytes
/**
* List here only the model IDs your endpoint exposes.
* Add/remove freely – nothing else in the codebase cares.
*/
export type ModelID = string;
let modelsCache: string[] | null = null;
export async function getModels(): Promise<string[]> {
if (modelsCache) {
return modelsCache;
}
try {
const response = await fetch("https://router.huggingface.co/v1/models");
const data = await response.json();
const modelIds = data.data.slice(0, 5).map((model: any) => model.id);
modelsCache = modelIds;
return modelIds;
} catch (e) {
console.error(e);
return [];
}
}
export async function getDefaultModel(): Promise<ModelID> {
const models = await getModels();
return models[0] ?? "";
}