HuggingFaceInference
这是一个调用 HugggingFaceInference 模型作为 LLM 的示例
- npm
- Yarn
- pnpm
npm install @langchain/community @langchain/core @huggingface/inference@2
yarn add @langchain/community @langchain/core @huggingface/inference@2
pnpm add @langchain/community @langchain/core @huggingface/inference@2
提示
我们正在统一所有包的模型参数。我们现在建议使用 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 });