跳到主要内容

HuggingFaceInference

这是一个调用 HugggingFaceInference 模型作为 LLM 的示例

npm install @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 });

此页是否对您有帮助?


您也可以留下详细的反馈 在 GitHub 上.