Skip to main content

HuggingFaceInference

以下是如何将 HuggingFaceInference 模型用作 LLM 的示例:

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", // 在 Node.js 中默认使用 process.env.HUGGINGFACEHUB_API_KEY
});
const res = await model.invoke("1 + 1 =");
console.log({ res });

相关内容


Was this page helpful?


You can also leave detailed feedback on GitHub.