Skip to main content

ChatDeepInfra

LangChain 通过 ChatDeepInfra 封装器支持 Deep Infra 托管的聊天模型。首先,你需要安装 @langchain/community 包:

:::提示 请参阅安装集成包的一般说明部分。 :::

npm install @langchain/community @langchain/core

你需要获取一个 API 密钥,并将其设置为名为 DEEPINFRA_API_TOKEN 的环境变量(或者直接传入构造函数),然后按照以下方式调用模型:

import { ChatDeepInfra } from "@langchain/community/chat_models/deepinfra";
import { HumanMessage } from "@langchain/core/messages";

const apiKey = process.env.DEEPINFRA_API_TOKEN;

const model = "meta-llama/Meta-Llama-3-70B-Instruct";

const chat = new ChatDeepInfra({
model,
apiKey,
});

const messages = [new HumanMessage("Hello")];

const res = await chat.invoke(messages);

console.log(res);

API Reference:

相关内容


Was this page helpful?


You can also leave detailed feedback on GitHub.