Documentation Index
Fetch the complete documentation index at: https://langchain-zh.cn/llms.txt
Use this file to discover all available pages before exploring further.
LangChain.js 支持调用 YandexGPT 聊天模型。
首先,您需要创建一个服务账户,并为其分配 ai.languageModels.user 角色。
接下来,您有两种身份验证选项:
- IAM 令牌。
您可以在构造函数参数中指定
iam_token,或在环境变量 YC_IAM_TOKEN 中设置。
- API 密钥。
您可以在构造函数参数中指定
api_key,或在环境变量 YC_API_KEY 中设置。
有关安装 LangChain 包的通用说明,请参阅此部分。
npm install @langchain/yandex @langchain/core
import { ChatYandexGPT } from "@langchain/yandex/chat_models";
import { HumanMessage, SystemMessage } from "@langchain/core/messages";
const chat = new ChatYandexGPT();
const res = await chat.invoke([
new SystemMessage(
"You are a helpful assistant that translates English to French."
),
new HumanMessage("I love programming."),
]);
console.log(res);
/*
AIMessage {
lc_serializable: true,
lc_kwargs: { content: "Je t'aime programmer.", additional_kwargs: {} },
lc_namespace: [ 'langchain', 'schema' ],
content: "Je t'aime programmer.",
name: undefined,
additional_kwargs: {}
}
*/
相关链接