ChatDeepSeek
这将帮助你开始使用 DeepSeek 聊天模型。有关 ChatDeepSeek
所有功能和配置的详细文档,请参阅 API 参考。
¥This will help you getting started with DeepSeek chat
models. For detailed documentation
of all ChatDeepSeek
features and configurations head to the API
reference.
概述
¥Overview
集成详情
¥Integration details
Class | Package | Local | Serializable | PY support | Package downloads | Package latest |
---|---|---|---|---|---|---|
ChatDeepSeek |
@langchain/deepseek |
❌ (see Ollama) | beta | ✅ | ![]() |
![]() |
模型特性
¥Model features
有关如何使用特定功能的指南,请参阅下方表格标题中的链接。
¥See the links in the table headers below for guides on how to use specific features.
Tool calling | Structured output | JSON mode | Image input | Audio input | Video input | Token-level streaming | Token usage | Logprobs |
---|---|---|---|---|---|---|---|---|
✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ |
请注意,自 2025 年 1 月 27 日起,deepseek-reasoner
目前不支持工具调用和结构化输出。
¥Note that as of 1/27/25, tool calling and structured output are not
currently supported for deepseek-reasoner
.
设置
¥Setup
要访问 DeepSeek 模型,你需要创建一个 DeepSeek 账户、获取 API 密钥并安装 @langchain/deepseek
集成包。
¥To access DeepSeek models you’ll need to create a DeepSeek account, get
an API key, and install the @langchain/deepseek
integration package.
你还可以通过 Together AI 或 Ollama 等提供程序访问 DeepSeek API。
¥You can also access the DeepSeek API through providers like Together AI or Ollama.
凭证
¥Credentials
前往 https://deepseek.com/ 注册 DeepSeek 并生成 API 密钥。完成此操作后,请设置 DEEPSEEK_API_KEY
环境变量:
¥Head to https://deepseek.com/ to sign up to DeepSeek and generate an API
key. Once you’ve done this set the DEEPSEEK_API_KEY
environment
variable:
export DEEPSEEK_API_KEY="your-api-key"
如果你想自动追踪模型调用,也可以通过取消注释以下内容来设置你的 LangSmith API 密钥:
¥If you want to get automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:
# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"
安装
¥Installation
LangChain ChatDeepSeek 集成位于 @langchain/deepseek
包中:
¥The LangChain ChatDeepSeek integration lives in the
@langchain/deepseek
package:
- npm
- yarn
- pnpm
npm i @langchain/deepseek @langchain/core
yarn add @langchain/deepseek @langchain/core
pnpm add @langchain/deepseek @langchain/core
实例化
¥Instantiation
现在我们可以实例化我们的模型对象并生成聊天补全:
¥Now we can instantiate our model object and generate chat completions:
import { ChatDeepSeek } from "@langchain/deepseek";
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.
链接
¥Chaining
我们可以使用如下提示模板对我们的模型进行 chain 操作:
¥We can chain our model with a prompt template like so:
import { ChatPromptTemplate } from "@langchain/core/prompts";
const prompt = ChatPromptTemplate.fromMessages([
[
"system",
"You are a helpful assistant that translates {input_language} to {output_language}.",
],
["human", "{input}"],
]);
const chain = prompt.pipe(llm);
await chain.invoke({
input_language: "English",
output_language: "German",
input: "I love programming.",
});
AIMessage {
"id": "6e7f6f8c-8d7a-4dad-be07-425384038fd4",
"content": "Ich liebe es zu programmieren.",
"additional_kwargs": {,
"reasoning_content": "...",
},
"response_metadata": {
"tokenUsage": {
"promptTokens": 18,
"completionTokens": 9,
"totalTokens": 27
},
"finish_reason": "stop",
"model_name": "deepseek-reasoner",
"usage": {
"prompt_tokens": 18,
"completion_tokens": 9,
"total_tokens": 27,
"prompt_tokens_details": {
"cached_tokens": 0
},
"prompt_cache_hit_tokens": 0,
"prompt_cache_miss_tokens": 18
},
"system_fingerprint": "fp_3a5770e1b4"
},
"tool_calls": [],
"invalid_tool_calls": [],
"usage_metadata": {
"output_tokens": 9,
"input_tokens": 18,
"total_tokens": 27,
"input_token_details": {
"cache_read": 0
},
"output_token_details": {}
}
}
API 参考
¥API reference
有关 ChatDeepSeek 所有功能和配置的详细文档,请参阅 API 参考:https://api.js.langchain.com/classes/_langchain_deepseek.ChatDeepSeek.html
¥For detailed documentation of all ChatDeepSeek features and configurations head to the API reference: https://api.js.langchain.com/classes/_langchain_deepseek.ChatDeepSeek.html