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

# ChatDeepSeek 集成

> 使用 LangChain Python 与 ChatDeepSeek 聊天模型集成。

这将帮助你开始使用 DeepSeek 的托管[聊天模型](/oss/python/langchain/models)。

<Tip>
  **API 参考**

  有关所有功能和配置选项的详细文档，请前往 [`ChatDeepSeek`](https://reference.langchain.com/python/langchain-deepseek/chat_models/ChatDeepSeek) API 参考。
</Tip>

<Tip>
  **DeepSeek 的模型是开源的，可以在本地运行（例如在 [Ollama](/oss/python/integrations/chat/ollama) 中），也可以在其他推理提供商（例如 [Fireworks](/oss/python/integrations/chat/fireworks)、[Together](/oss/python/integrations/chat/together)）上运行。**
</Tip>

## 概述

### 集成详情

| 类                                                                                                    | 包                                                                                  | 可序列化 | [JS 支持](https://js.langchain.com/docs/integrations/chat/deepseek) |                                                 下载量                                                 |                                                版本                                                |
| :--------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | :--: | :---------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------: |
| [`ChatDeepSeek`](https://reference.langchain.com/python/langchain-deepseek/chat_models/ChatDeepSeek) | [`langchain-deepseek`](https://reference.langchain.com/python/langchain-deepseek/) | beta |                                 ✅                                 | ![PyPI - Downloads](https://img.shields.io/pypi/dm/langchain-deepseek?style=flat-square\&label=%20) | ![PyPI - Version](https://img.shields.io/pypi/v/langchain-deepseek?style=flat-square\&label=%20) |

### 模型功能

| [工具调用](/oss/python/langchain/tools) | [结构化输出](/oss/python/langchain/structured-output) | [图像输入](/oss/python/langchain/messages#multimodal) | 音频输入 | 视频输入 | [令牌级流式传输](/oss/python/langchain/streaming/) | 原生异步 | [令牌使用量](/oss/python/langchain/models#token-usage) | [对数概率](/oss/python/langchain/models#log-probabilities) |
| :---------------------------------: | :----------------------------------------------: | :-----------------------------------------------: | :--: | :--: | :-----------------------------------------: | :--: | :-----------------------------------------------: | :----------------------------------------------------: |
|                  ✅                  |                         ✅                        |                         ❌                         |   ❌  |   ❌  |                      ✅                      |   ✅  |                         ✅                         |                            ❌                           |

<Note>
  **通过 `model="deepseek-reasoner"` 指定的 DeepSeek-R1 不支持工具调用或结构化输出。这些功能[受支持](https://api-docs.deepseek.com/guides/function_calling)于 DeepSeek-V3（通过 `model="deepseek-chat"` 指定）。**
</Note>

## 设置

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

### 凭证

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

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import getpass
import os

if not os.getenv("DEEPSEEK_API_KEY"):
    os.environ["DEEPSEEK_API_KEY"] = getpass.getpass("Enter your DeepSeek API key: ")
```

要启用模型调用的自动跟踪，请设置你的 [LangSmith](/langsmith/home) API 密钥：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
os.environ["LANGSMITH_TRACING"] = "true"
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
```

### 安装

LangChain DeepSeek 集成位于 `langchain-deepseek` 包中：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
pip install -qU langchain-deepseek
```

## 实例化

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

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_deepseek import ChatDeepSeek

llm = ChatDeepSeek(
    model="deepseek-chat",
    temperature=0,
    max_tokens=None,
    timeout=None,
    max_retries=2,
    # other params...
)
```

## 调用

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
messages = [
    (
        "system",
        "You are a helpful assistant that translates English to French. Translate the user sentence.",
    ),
    ("human", "I love programming."),
]
ai_msg = llm.invoke(messages)
ai_msg.content
```

***

## API 参考

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

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档](/use-these-docs)通过 MCP 连接到 Claude、VSCode 等，以获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/chat/deepseek.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
