Skip to main content

ChatYandexGPT

LangChain.js supports calling YandexGPT chat models.

Setup

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

Next, you have two authentication options:

  • IAM token. You can specify the token in a constructor parameter as iam_token or in an environment variable YC_IAM_TOKEN.
  • 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
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:


Was this page helpful?


You can also leave detailed feedback on GitHub.