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 variableYC_IAM_TOKEN
. - API key
You can specify the key in a constructor parameter as
api_key
or in an environment variableYC_API_KEY
.
Usage
- npm
- Yarn
- pnpm
npm install @langchain/yandex @langchain/core
yarn add @langchain/yandex @langchain/core
pnpm add @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:
- ChatYandexGPT from
@langchain/yandex/chat_models
- HumanMessage from
@langchain/core/messages
- SystemMessage from
@langchain/core/messages
Related
- Chat model conceptual guide
- Chat model how-to guides