Skip to main content
此类已弃用。请改用 @langchain/baidu-qianfan 包。
LangChain.js 支持百度的文心一言(ERNIE-bot)系列模型。示例如下:
请参阅此部分以获取有关安装 LangChain 包的常规说明。
npm
npm install @langchain/community @langchain/core
可用模型:ERNIE-BotERNIE-Bot-turboERNIE-Bot-4ERNIE-Speed-8KERNIE-Speed-128KERNIE-4.0-8KERNIE-4.0-8K-PreviewERNIE-3.5-8KERNIE-3.5-8K-PreviewERNIE-Lite-8KERNIE-Tiny-8KERNIE-Character-8KERNIE Speed-AppBuilder 已废弃模型:ERNIE-Bot-turbo
import { ChatBaiduWenxin } from "@langchain/community/chat_models/baiduwenxin";
import { HumanMessage } from "@langchain/core/messages";

// Default model is ERNIE-Bot-turbo
const ernieTurbo = new ChatBaiduWenxin({
  baiduApiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.BAIDU_API_KEY
  baiduSecretKey: "YOUR-SECRET-KEY", // In Node.js defaults to process.env.BAIDU_SECRET_KEY
});

// Use ERNIE-Bot
const ernie = new ChatBaiduWenxin({
  model: "ERNIE-Bot", // Available models are shown above
  temperature: 1,
  baiduApiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.BAIDU_API_KEY
  baiduSecretKey: "YOUR-SECRET-KEY", // In Node.js defaults to process.env.BAIDU_SECRET_KEY
});

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

let res = await ernieTurbo.invoke(messages);
/*
AIChatMessage {
  text: 'Hello! How may I assist you today?',
  name: undefined,
  additional_kwargs: {}
  }
}
*/

res = await ernie.invoke(messages);
/*
AIChatMessage {
  text: 'Hello! How may I assist you today?',
  name: undefined,
  additional_kwargs: {}
  }
}
*/

相关