跳到主要内容
LangChain.js 支持 Moonshot AI 系列模型。 https://platform.moonshot.cn/docs/intro

设置

你需要注册一个 Moonshot API 密钥并将其设置为名为 MOONSHOT_API_KEY 的环境变量 https://platform.moonshot.cn/console 你还需要安装以下依赖项:
有关安装 LangChain 软件包的一般说明,请参阅此部分
npm
npm install @langchain/community @langchain/core

用法

以下是一个示例
import { ChatMoonshot } from "@langchain/community/chat_models/moonshot";
import { HumanMessage } from "@langchain/core/messages";

// Default model is moonshot-v1-8k
const moonshotV18K = new ChatMoonshot({
  apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.MOONSHOT_API_KEY
});

// Use moonshot-v1-128k
const moonshotV1128k = new ChatMoonshot({
  apiKey: "YOUR-API-KEY", // In Node.js defaults to process.env.MOONSHOT_API_KEY
  model: "moonshot-v1-128k", // Available models: moonshot-v1-8k, moonshot-v1-32k, moonshot-v1-128k
  temperature: 0.3,
});

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

const res = await moonshotV18K.invoke(messages);
/*
AIMessage {
  content: "Hello! How can I help you today? Is there something you would like to talk about or ask about? I'm here to assist you with any questions you may have.",
}
*/

const res2 = await moonshotV1128k.invoke(messages);
/*
AIMessage {
  text: "Hello! How can I help you today? Is there something you would like to talk about or ask about? I'm here to assist you with any questions you may have.",
}
*/

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