ChatDeepSeek
这将帮助您开始使用 DeepSeek 托管的 聊天模型。有关 ChatDeepSeek 所有功能和配置的详细文档,请参阅 API 参考。
概述
集成详情
类别 | 包 | 本地 | 可序列化 | JS 支持 | 包下载量 | 最新包版本 |
---|---|---|---|---|---|---|
ChatDeepSeek | langchain-deepseek | ❌ | 测试版 | ✅ |
模型特性
工具调用 | 结构化输出 | JSON 模式 | 图片输入 | 音频输入 | 视频输入 | 逐令牌流式传输 | 原生异步 | 令牌使用量 | 对数概率 |
---|---|---|---|---|---|---|---|---|---|
✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ❌ |
注意
DeepSeek-R1(通过 model="deepseek-reasoner"
指定)不支持工具调用或结构化输出。这些功能 受支持 通过 DeepSeek-V3(通过 model="deepseek-chat"
指定)。
设置
要访问 DeepSeek 模型,您需要创建一个 DeepSeek 帐户,获取一个 API 密钥,并安装 langchain-deepseek
集成包。
凭证
前往 DeepSeek 的 API 密钥页面 注册 DeepSeek 并生成一个 API 密钥。完成后,设置 DEEPSEEK_API_KEY
环境变量。
import getpass
import os
if not os.getenv("DEEPSEEK_API_KEY"):
os.environ["DEEPSEEK_API_KEY"] = getpass.getpass("Enter your DeepSeek API key: ")
要启用模型调用的自动跟踪,请设置您的 LangSmith API 密钥
# os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
安装
LangChain DeepSeek 集成位于 langchain-deepseek
包中。
%pip install -qU langchain-deepseek
实例化
现在我们可以实例化模型对象并生成聊天补全
from langchain_deepseek import ChatDeepSeek
llm = ChatDeepSeek(
model="deepseek-chat",
temperature=0,
max_tokens=None,
timeout=None,
max_retries=2,
# other params...
)
API 参考:ChatDeepSeek
调用
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
链式调用
我们可以像这样将模型与提示模板链式连接起来
from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate(
[
(
"system",
"You are a helpful assistant that translates {input_language} to {output_language}.",
),
("human", "{input}"),
]
)
chain = prompt | llm
chain.invoke(
{
"input_language": "English",
"output_language": "German",
"input": "I love programming.",
}
)
API 参考:ChatPromptTemplate
API 参考
有关 ChatDeepSeek 所有功能和配置的详细文档,请参阅 API 参考。