> ## 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.

# ChatYandexGPT 集成

> 使用 LangChain JavaScript 集成 ChatYandexGPT 聊天模型。

LangChain.js 支持调用 [YandexGPT](https://cloud.yandex.com/en/services/yandexgpt) 聊天模型。

## 设置

首先，您需要[创建一个服务账户](https://cloud.yandex.com/en/docs/iam/operations/sa/create)，并为其分配 `ai.languageModels.user` 角色。

接下来，您有两种身份验证选项：

* [IAM 令牌](https://cloud.yandex.com/en/docs/iam/operations/iam-token/create-for-sa)。
  您可以在构造函数参数中指定 `iam_token`，或在环境变量 `YC_IAM_TOKEN` 中设置。
* [API 密钥](https://cloud.yandex.com/en/docs/iam/operations/api-key/create)。
  您可以在构造函数参数中指定 `api_key`，或在环境变量 `YC_API_KEY` 中设置。

## 使用

<Tip>
  有关安装 LangChain 包的通用说明，请参阅[此部分](/oss/javascript/langchain/install)。
</Tip>

```bash npm theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
npm install @langchain/yandex @langchain/core
```

```typescript theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
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: {}
}
 */
```

## 相关链接

* 聊天模型[概念指南](/oss/javascript/langchain/models)
* 聊天模型[操作指南](/oss/javascript/langchain/models)

***

<div className="source-links">
  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/i18n\zh-CN\oss\javascript\integrations\chat\yandex.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>

  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>
</div>
