Skip to main content

ChatYandexGPT

LangChain.js 支持调用 YandexGPT 聊天模型。

¥LangChain.js supports calling YandexGPT chat models.

设置

¥Setup

首先,你需要使用 ai.languageModels.user 角色登录 创建服务账户

¥First, you should create a service account with the ai.languageModels.user role.

接下来,你有两个身份验证选项:

¥Next, you have two authentication options:

  • IAM 令牌。你可以在构造函数参数中将令牌指定为 iam_token,也可以在环境变量 YC_IAM_TOKEN 中指定令牌。

    ¥IAM token. You can specify the token in a constructor parameter as iam_token or in an environment variable YC_IAM_TOKEN.

  • API 密钥 你可以在构造函数参数中将键指定为 api_key,也可以在环境变量 YC_API_KEY 中指定键。

    ¥API key You can specify the key in a constructor parameter as api_key or in an environment variable YC_API_KEY.

用法

¥Usage

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: {}
}
*/

API Reference:

¥Related