HuggingFaceInference
以下是如何将 HuggingFaceInference 模型用作 LLM 的示例:
- npm
- Yarn
- pnpm
npm install @langchain/community @langchain/core @huggingface/inference@4
yarn add @langchain/community @langchain/core @huggingface/inference@4
pnpm add @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 });
相关内容
Related
- LLM conceptual guide
- LLM how-to guides