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

# ChatDeepSeek 集成

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

本指南将帮助您开始使用 DeepSeek's hosted [聊天模型](/oss/python/langchain/models).

<Tip>
  **API 参考**

  有关所有 features and configuration options, 请前往 [`ChatDeepSeek`](https://reference.langchain.com/python/langchain-deepseek/chat_models/ChatDeepSeek) API reference.
</Tip>

<Tip>
  **DeepSeek's models are open source and can be run locally (e.g. in [Ollama](/oss/python/integrations/chat/ollama)) or on other inference providers (e.g. [Fireworks](/oss/python/integrations/chat/fireworks), [Together](/oss/python/integrations/chat/together)) as well.**
</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) |

### 模型功能

| [Tool calling](/oss/python/langchain/tools) | [Structured output](/oss/python/langchain/structured-output) | [Image input](/oss/python/langchain/messages#multimodal) | 音频输入 | 视频输入 | [Token-level streaming](/oss/python/langchain/streaming/) | 原生异步 | [Token usage](/oss/python/langchain/models#token-usage) | [Logprobs](/oss/python/langchain/models#log-probabilities) |
| :-----------------------------------------: | :----------------------------------------------------------: | :------------------------------------------------------: | :--: | :--: | :-------------------------------------------------------: | :--: | :-----------------------------------------------------: | :--------------------------------------------------------: |
|                      ✅                      |                               ✅                              |                             ❌                            |   ❌  |   ❌  |                             ✅                             |   ✅  |                            ✅                            |                              ❌                             |

<Note>
  **DeepSeek-R1, specified via `model="deepseek-reasoner"`, does not support tool calling or structured output. Those features [are supported](https://api-docs.deepseek.com/guides/function_calling) by DeepSeek-V3 (specified via `model="deepseek-chat"`).**
</Note>

## 设置

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

### 凭证

前往 [DeepSeek's API Key page](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 key:

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
os.environ["LANGSMITH_TRACING"] = "true"
os.environ["LANGSMITH_API_KEY"] = getpass.getpass("请输入您的 LangSmith API 密钥: ")
```

### 安装

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,
    # 其他参数...
)
```

## 调用

```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 Reference](https://reference.langchain.com/python/langchain-deepseek/chat_models/ChatDeepSeek).

***

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

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/chat/deepseek.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
