npm
We've raised a $125M Series B to build the platform for agent engineering. Read more.
npm install @langchain/community @langchain/core @huggingface/inference@4
model instead of modelName, and apiKey for API keys.import { HuggingFaceInference } from "@langchain/community/llms/hf";
const model = new HuggingFaceInference({
model: "gpt2",
apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.HUGGINGFACEHUB_API_KEY
});
const res = await model.invoke("1 + 1 =");
console.log({ res });