跳到主要内容
以下是将 HuggingFaceInference 模型作为 LLM 调用的示例
npm
npm install @langchain/community @langchain/core @huggingface/inference@4
我们正在统一所有包的模型参数。现在我们建议使用 model 而不是 modelName,并使用 apiKey 来表示 API 密钥。
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 });

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.