Hugging Face
Hugging face is a machine learning community where you can share pre trained models and explore other trained models, which are suited for many use cases.
Many of the models already trained well and ready to use. Without delay get started!
Initialize a node project
Initialize a node project by creating and run npm init on the terminal, this will create the basic package.json file.
Make sure that you are registered on HuggingFace and copied the TOCKEN.
No create mistel.js file for running mistrel lang model.
// mstrel.js
import { HfInference } from "@huggingface/inference";
const HF_TOKEN = "Your HugginFaceTocken";
const hf = new HfInference(HF_TOKEN);
const prompt ="Who am Christopher"
const res= await hf.textGeneration({
model:"mistralai/Mixtral-8x7B-Instruct-v0.1", inputs:prompt
})
console.log(res);
In the package.json add new script for running the file.
{
"name": "hf",
"type": "module",
"version": "1.0.0",
"description": "",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev1": "node mistrel.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"@huggingface/inference": "^2.6.4"
}
}
In this example we are using mistralai/Mixtral-8x7B-Instruct-v0.1 model. Make sure the dependency (@huggingface/inference) installed correctly using np install or yarn install
Now we are ready to test the script.
npm run dev
mistrel model will complete the sentence for you.
In this way we can accommodate ML in our React / or any JavaScript Framework projects