跳到主要内容
此类已弃用。请改用 @langchain/baidu-qianfan 包。
LangChain.js 支持百度文心大模型家族。以下是一个示例:
有关安装 LangChain 软件包的一般说明,请参阅此部分
npm
npm install @langchain/community @langchain/core
可用模型:ERNIE-Bot,ERNIE-Bot-turbo,ERNIE-Bot-4,ERNIE-Speed-8K,ERNIE-Speed-128K,ERNIE-4.0-8K, ERNIE-4.0-8K-Preview,ERNIE-3.5-8K,ERNIE-3.5-8K-Preview,ERNIE-Lite-8K,ERNIE-Tiny-8K,ERNIE-Character-8K, ERNIE 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: {}
  }
}
*/

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.