> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-docs-zh.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# ChatDeepSeek 集成

> 集成 ChatDeepSeek 对话模型使用 LangChain JavaScript.

这将帮助你开始使用 `ChatDeepSeek` [对话模型](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/models.md)。有关所有 `ChatDeepSeek` 功能和配置的详细文档，请访问 [API 参考](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek)。

## 概述

### 集成详情

| 类 | 包 | 可序列化 | [PY 支持](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/chat/deepseek.md) | 下载量 | 版本 |
| :- | :- | :-: | :-: | :-: | :-: |
| [`ChatDeepSeek`](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek) | [`@langchain/deepseek`](https://npmjs.com/@langchain/deepseek) | beta | ✅ | ![NPM - 下载量](https://img.shields.io/npm/dm/@langchain/deepseek?style=flat-square\&label=%20&) | ![NPM - 版本](https://img.shields.io/npm/v/@langchain/deepseek?style=flat-square\&label=%20&) |

### 模型功能

请查看下表标题中的链接，了解如何使用特定功能。

| [工具调用](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/tools.md) | [结构化输出](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/structured-output.md) | [图像输入](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/messages.md#多模态) | 音频输入 | 视频输入 | [Token 级流式输出](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/streaming.md) | [Token 使用量](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/models.md#token-使用) | [Logprobs](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/models.md#对数概率) |
| :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: |
| ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ |

请注意，截至 2025 年 1 月 27 日，工具调用和结构化输出目前不支持 `deepseek-reasoner`。

## 设置

要访问 DeepSeek 模型，你需要创建一个 DeepSeek 账户，获取一个 API 密钥，并安装 `@langchain/deepseek` 集成包。

你也可以通过 [Ollama](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/chat/ollama.md) 等提供程序访问 DeepSeek API。

### 凭证

前往 [deepseek.com](https://deepseek.com/) 注册 DeepSeek 并生成 API 密钥。完成后，设置 `DEEPSEEK_API_KEY` 环境变量：

```bash theme={null}
export DEEPSEEK_API_KEY="your-api-key"
```

如果你希望自动跟踪你的模型调用，可以通过取消注释以下内容来设置你的 [LangSmith](https://docs.langchain.com/langsmith/observability) API 密钥：

```bash theme={null}
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"
```

### 安装

LangChain ChatDeepSeek 集成位于 `@langchain/deepseek` 包中：

```bash npm theme={null}
npm install @langchain/deepseek @langchain/core
```

```bash yarn theme={null}
yarn add @langchain/deepseek @langchain/core
```

```bash pnpm theme={null}
pnpm add @langchain/deepseek @langchain/core
```

## 实例化

现在我们可以实例化我们的模型对象并生成对话补全：

```typescript theme={null}
import { ChatDeepSeek } from "@langchain/deepseek";

const llm = new ChatDeepSeek({
  model: "deepseek-reasoner",
  temperature: 0,
  // other params...
})
```

```typescript theme={null}
const aiMsg = await llm.invoke([
  [
    "system",
    "You are a helpful assistant that translates English to French. Translate the user sentence.",
  ],
  ["human", "I love programming."],
])
aiMsg
```

```text theme={null}
AIMessage {
  "id": "e2874482-68a7-4552-8154-b6a245bab429",
  "content": "J'adore la programmation.",
  "additional_kwargs": {
    "reasoning_content": "..."
  },
  "response_metadata": {
    "tokenUsage": {
      "promptTokens": 23,
      "completionTokens": 7,
      "totalTokens": 30
    },
    "finish_reason": "stop",
    "model_name": "deepseek-reasoner",
    "usage": {
      "prompt_tokens": 23,
      "completion_tokens": 7,
      "total_tokens": 30,
      "prompt_tokens_details": {
        "cached_tokens": 0
      },
      "prompt_cache_hit_tokens": 0,
      "prompt_cache_miss_tokens": 23
    },
    "system_fingerprint": "fp_3a5770e1b4"
  },
  "tool_calls": [],
  "invalid_tool_calls": [],
  "usage_metadata": {
    "output_tokens": 7,
    "input_tokens": 23,
    "total_tokens": 30,
    "input_token_details": {
      "cache_read": 0
    },
    "output_token_details": {}
  }
}
```

```typescript theme={null}
console.log(aiMsg.content)
```

```text theme={null}
J'adore la programmation.
```

***

## API 参考

有关所有 `ChatDeepSeek` 功能和配置的详细文档，请访问 [API 参考](https://reference.langchain.com/javascript/langchain-deepseek/ChatDeepSeek)。

***

> 官方原文：[src/oss/javascript/integrations/chat/deepseek.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/javascript/integrations/chat/deepseek.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.