huggingface / huggingface.js

Utilities to use the Hugging Face Hub API
https://hf.co/docs/huggingface.js
MIT License
1.42k stars 229 forks source link

validate HF Token #237

Closed satpalsr closed 11 months ago

satpalsr commented 1 year ago

const inference = new HfInference(HF_ACCESS_TOKEN);

It would be good to validate the HF Token here. I am following up vercel ai sdk HF example and want to return an error in case of invalid token.

coyotte508 commented 1 year ago

you can use @huggingface/hub

import { whoAmI } from "@huggingface/hub";

const info = await whoAmI({credentials: {accessToken: "hf_XXX"}});
console.log(info);