这将帮助您开始使用 ChatDeepSeek 聊天模型。有关所有 ChatDeepSeek 功能和配置的详细文档,请前往 API 参考.
## 概述 ### 集成详情
| 类 | 包 | 可序列化 | Python 支持 | 下载量 | 版本 |
|---|---|---|---|---|---|
ChatDeepSeek | @langchain/deepseek | beta | ✅ | <img src="https://img.shields.io/npm/dm/@langchain/deepseek?style=flat-square&label=%20&" alt="NPM - Downloads" /> | <img src="https://img.shields.io/npm/v/@langchain/deepseek?style=flat-square&label=%20&" alt="NPM - Version" /> |
模型特性
请参阅下表标题中的链接,了解如何使用特定功能。
| 工具调用 | 结构化输出 | 图像输入 | 音频输入 | 视频输入 | Token 级流式输出 | Token 使用量 | 对数概率 |
|---|---|---|---|---|---|---|---|
| ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ |
Note that as of 1/27/25, tool calling and structured output are not currently supported for deepseek-reasoner.
设置
要访问 DeepSeek 模型,您需要创建一个 DeepSeek 账户,获取 API 密钥,并安装 @langchain/deepseek 集成包。
您也可以通过以下提供商访问 DeepSeek API,例如 Ollama.
凭据
前往 deepseek.com 注册 DeepSeek 并生成 API 密钥。完成后设置 DEEPSEEK_API_KEY 环境变量:
如果您想获取模型调用的自动跟踪,还可以设置您的 LangSmith API 密钥(取消下方注释):
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"
安装
LangChain ChatDeepSeek 集成位于 @langchain/deepseek package:
npm install @langchain/deepseek @langchain/core
yarn add @langchain/deepseek @langchain/core
pnpm add @langchain/deepseek @langchain/core
实例化
现在我们可以实例化模型对象并生成聊天补全:
const llm = new ChatDeepSeek({
model: "deepseek-reasoner",
temperature: 0,
// other params...
})
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
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": {}
}
}
console.log(aiMsg.content)
J'adore la programmation.
API 参考
有关所有 ChatDeepSeek 功能和配置的详细文档,请前往 API 参考.